Git Product home page Git Product logo

Comments (4)

Nickersoft avatar Nickersoft commented on August 22, 2024 1

Hey @ElecTwix,

Sorry for the delay – just got around to looking at this. I did a bit more digging and it looks like it's a bug with SurrealDB and schemafull tables. If I make my table schemaless it works as expected, despite the record links being stored as an array of strings. I can use the dot notation to reference nested fields. Going to close this, as I'm tracking it on the main repo now. Thanks for all the help!

from surrealdb.go.

ElecTwix avatar ElecTwix commented on August 22, 2024

If you are trying to create an array of records Golang SDK does not support bulk creation such as array but it is planned to have.

If thats is not the case:
Could you give me an example to reproduce the issue?

from surrealdb.go.

Nickersoft avatar Nickersoft commented on August 22, 2024

Hey @ElecTwix! Thanks for the quick response – to clarify, I'm not trying to create records in bulk, just store an array of record links as a column on one of my tables. My example repo is a bit complex ATM, and I'd need to carve out time to create an MVP.

That said, the general steps I'd follow to reproduce are:

  1. Using either SurrealQL or a GUI like Surrealist (what I used), create a schemafull table (e.g. "table1") that has a column of type set<record>
  2. Create another table (e.g. "table2") that stores some data for the new column to reference
  3. Using the SDK, attempt to create a new table row that references the test table:
db.Create("table1", map[string]interface{}{
  "links": []string{"table2:1234"}
}

This is effectively the approach I'm trying, except the query passes but links would still be [] in the database.

from surrealdb.go.

ElecTwix avatar ElecTwix commented on August 22, 2024

Hi @Nickersoft!

I created basic program for doing something similar I know is very dirty but it should work
Also I wanted to note this is schemaless but I think it will work schemafull when change the user creation part

package main

import (
	"fmt"

	_ "github.com/rs/zerolog"
	"github.com/surrealdb/surrealdb.go"
	"github.com/surrealdb/surrealdb.go/pkg/gorilla"
)

type User struct {
	Name    string
	Surname string
	Friends []string
}

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

	// Sign in
	if _, err = db.Signin(map[string]string{
		"user": "root",
		"pass": "root",
	}); err != nil {
		panic(err)
	}

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

	var recordArr []string

	for i := 0; i < 10; i++ {
		user := User{
			Name: fmt.Sprintf("John %d", i),
		}
		_, err := db.Create(fmt.Sprintf("user:%d", i), user)
		if err != nil {
			panic(err)
		}
		recordArr = append(recordArr, fmt.Sprintf("user:%d", i))
	}

	// Create user struct
	user := User{
		Name:    "John",
		Surname: "Doe",
		Friends: recordArr,
	}

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

	fmt.Println(data)

}
Output:
[map[Friends:[user:0 user:1 user:2 user:3 user:4 user:5 user:6 user:7 user:8 user:9] Name:John Surname:Doe id:user:7b6z7d17dex59f4rd7yq]]

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.