Comments (4)
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.
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.
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:
- 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>
- Create another table (e.g. "table2") that stores some data for the new column to reference
- 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.
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)
- Feature: context.Context Support HOT 6
- Feature: Move and test `unmarshalMapToStruct(data map[string]interface{}, outStruct interface{})` HOT 2
- Bug: Re-connection to the DB HOT 2
- Bug: Broken Tests for Fetch HOT 5
- Bug: Unhandled errors in websockets can lead to panics HOT 4
- Bug: `Question or idea` Button HOT 2
- surrealdb Auth undefined HOT 1
- Bug: unexpected EOF on TestSurrealDBSuite/gorilla/TestUpdate HOT 1
- Documentation: The README file example is not usable with the latest main branch, neither with the latest version HOT 1
- Feature: Replace Gorilla WS with Nhooyr WS HOT 7
- Bug: The session has expired error when connecting to version 1.3.0 HOT 4
- Bug: stack overflow error in gorilla websocket with db version 1.3.0 HOT 4
- Feature: surrealML for golang
- Documentation: Add Documentation for .Live() func & other stuff related to LIVE queries HOT 6
- Change function does not exist HOT 3
- Feature: Add CBOR support HOT 2
- Bug: UnmarshalRaw panics when unmarshalling object HOT 3
- Feature: UPSERT
- Example fails in Beta 11 - panic: sending request failed for method 'change': Method not found HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from surrealdb.go.