From a6b732424ac839196adeb7d0d579835f27076de9 Mon Sep 17 00:00:00 2001 From: sbshah97 Date: Thu, 16 Nov 2023 23:28:09 +0000 Subject: [PATCH 1/2] Updated README for surrealdb go driver --- README.md | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c5857bc..4d4ca02 100644 --- a/README.md +++ b/README.md @@ -17,37 +17,39 @@ The official SurrealDB library for Golang. go get github.com/surrealdb/surrealdb.go ``` -### Usage +### Quick Start ```go package main - import ( - "fmt" - "github.com/surrealdb/surrealdb.go" + "github.com/surrealdb/surrealdb.go" + ) +type User struct { + ID string `json:"id,omitempty"` + Name string `json:"name"` + Surname string `json:"surname"` +} + func main() { - // Connect to SurrealDB db, err := surrealdb.New("ws://localhost:8000/rpc") if err != nil { panic(err) } - // Sign in - if _, err = db.Signin(map[string]string{ + if _, err = db.Signin(map[string]interface{}{ "user": "root", "pass": "root", }); err != nil { panic(err) } - // Select namespace and database if _, err = db.Use("test", "test"); err != nil { panic(err) } - // Create user struct + // Create user user := User{ Name: "John", Surname: "Doe", @@ -81,16 +83,12 @@ func main() { // Change part/parts of user changes := map[string]string{"name": "Jane"} - if _, err = db.Change(selectedUser.ID, changes); err != nil { - panic(err) - } // Update user if _, err = db.Update(selectedUser.ID, changes); err != nil { panic(err) } - // Raw Query user if _, err = db.Query("SELECT * FROM $record", map[string]interface{}{ "record": createdUser[0].ID, }); err != nil { @@ -101,10 +99,17 @@ func main() { if _, err = db.Delete(selectedUser.ID); err != nil { panic(err) } -} +} ``` +* Step 1: Create a file called `main.go` and paste the above code +* Step 2: Run the command `go mod init github.com//` to create a go.mod file +* Step 3: Run the command `go mod tidy` to download surreal db +* Step 4: Run `go run main.go` to run the application. + +Note: Would be helpful to add `fmt.Println` statements to debug. + # Documentation Full documentation is available at [surrealdb doc](https://surrealdb.com/docs/integration/libraries/golang) From 0f791d019c8c145f39cdfde8feeefe5db7b61f5b Mon Sep 17 00:00:00 2001 From: sbshah97 Date: Sun, 19 Nov 2023 23:20:26 +0000 Subject: [PATCH 2/2] Updated commit to match review comments --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4d4ca02..57deb72 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,15 @@ The official SurrealDB library for Golang. ## Getting Started +For instructions on how to follow SurrealDB, follow [Installation Guide](https://surrealdb.com/docs/installation) + ### Installation ```bash go get github.com/surrealdb/surrealdb.go ``` -### Quick Start +### Usage ```go package main @@ -33,12 +35,13 @@ type User struct { } func main() { + // Connect to SurrealDB db, err := surrealdb.New("ws://localhost:8000/rpc") if err != nil { panic(err) } - if _, err = db.Signin(map[string]interface{}{ + if _, err = db.Signin(map[string]string{ "user": "root", "pass": "root", }); err != nil { @@ -49,7 +52,7 @@ func main() { panic(err) } - // Create user + // Define user struct user := User{ Name: "John", Surname: "Doe", @@ -99,7 +102,6 @@ func main() { if _, err = db.Delete(selectedUser.ID); err != nil { panic(err) } - } ``` @@ -108,8 +110,6 @@ func main() { * Step 3: Run the command `go mod tidy` to download surreal db * Step 4: Run `go run main.go` to run the application. -Note: Would be helpful to add `fmt.Println` statements to debug. - # Documentation Full documentation is available at [surrealdb doc](https://surrealdb.com/docs/integration/libraries/golang)