Git Product home page Git Product logo

Comments (6)

sbshah97 avatar sbshah97 commented on July 21, 2024 1

https://github.com/surrealdb/surrealdb.go/pull/90/files#diff-ac94c91f8ea84762d55b6932ef1466a2165984591d3e646360c5bb31b2130900

I think this PR typically solves this. We are now using smart unmarshal instead of the older code which used to use, unmarshal from db.go @ElecTwix let me know if this assumption is correct and we should be okay to close this?

from surrealdb.go.

phughk avatar phughk commented on July 21, 2024 1

Will close as it looks solved, but @jonsaw (or anyone else) please let us know if it isn't and we can re-open.

from surrealdb.go.

phughk avatar phughk commented on July 21, 2024

Thanks! We will test this case in the unit/integration tests.

from surrealdb.go.

sbshah97 avatar sbshah97 commented on July 21, 2024

Hi, I was trying to reproduce this and wrote the following code. From my understanding this is now resolved.

package main

import (
	"fmt"

	"github.com/surrealdb/surrealdb.go"
)

type User struct {
	Name    string
	ID      string
	Surname string
}

func main() {
	// Connect to SurrealDB
	db, err := surrealdb.New("ws://localhost:8000/rpc")
	if err != nil {
		panic(err)
	}

	// Select namespace and database
	if _, err = db.Use("test", "test"); err != nil {
		panic(err)
	}

	// Create user struct
	user := User{
		Name:    "Salman",
		Surname: "Shah",
	}

	// Insert user
	data, err := db.Create("user", user)
	if err != nil {
		panic(err)
	}

	fmt.Println("User created", data)

	// Unmarshal data
	createdUser := make([]User, 1)
	err = surrealdb.Unmarshal(data, &createdUser)
	if err != nil {
		panic(err)
	}

	fmt.Println("Created user after unmarshal", createdUser)

	// Get user by ID
	data, err = db.Select(createdUser[0].ID)
	if err != nil {
		panic(err)
	}

	// Unmarshal data
	selectedUser := new(User)
	err = surrealdb.Unmarshal(data, &selectedUser)
	if err != nil {
		panic(err)
	}

	fmt.Println("Selected user", selectedUser)

	fmt.Println(selectedUser.ID)

	// Update user
	surrealUser, err := db.Update("user:4ghv324dzhg3chxk4jbs", map[string]string{"name": "Jane"})
	if err != nil {
		panic(err)
	}

	var updatedUser User
	err = surrealdb.Unmarshal(surrealUser, &updatedUser)
	if err != nil {
		fmt.Println("Error in unmarshalling", err)
	}

	// Raw Query user
	if _, err = db.Query("SELECT $rowName FROM $record", map[string]interface{}{
		"record":  createdUser[0].ID,
		"rowName": "name",
	}); err != nil {
		panic(err)
	}

	fmt.Println("Deleting user by ID", selectedUser)
	// Delete user by ID
	if _, err = db.Delete(selectedUser.ID); err != nil {
		panic(err)
	}
}

from surrealdb.go.

sbshah97 avatar sbshah97 commented on July 21, 2024

Happy to add a test case for this though if it doesn't exist

from surrealdb.go.

ElecTwix avatar ElecTwix commented on July 21, 2024

I think this PR typically solves this. We are now using smart unmarshal instead of the older code which used to use, unmarshal from db.go @ElecTwix let me know if this assumption is correct and we should be okay to close this?

Thanks for your effort.
I couldn't reproduce either like you said I belive it fixed when refactored.

from surrealdb.go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.