{"id":16440800,"url":"https://github.com/idevelopthings/surrealdb.go.unofficial","last_synced_at":"2025-10-08T17:54:49.372Z","repository":{"id":61627399,"uuid":"546641366","full_name":"iDevelopThings/surrealdb.go.unofficial","owner":"iDevelopThings","description":"Unofficial fork of surrealdb.go package with some ease of use modifications ","archived":false,"fork":false,"pushed_at":"2022-10-09T18:09:44.000Z","size":53,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-08T15:07:59.983Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iDevelopThings.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2022-10-06T12:08:06.000Z","updated_at":"2023-02-25T17:18:23.000Z","dependencies_parsed_at":"2022-10-19T19:00:33.251Z","dependency_job_id":null,"html_url":"https://github.com/iDevelopThings/surrealdb.go.unofficial","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb.go.unofficial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb.go.unofficial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb.go.unofficial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iDevelopThings%2Fsurrealdb.go.unofficial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iDevelopThings","download_url":"https://codeload.github.com/iDevelopThings/surrealdb.go.unofficial/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240774197,"owners_count":19855353,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-11T09:13:05.887Z","updated_at":"2025-10-08T17:54:44.325Z","avatar_url":"https://github.com/iDevelopThings.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003esurrealdb.go\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca align=\"center\" href=\"https://goreportcard.com/report/github.com/idevelopthings/surrealdb.go.unofficial\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://goreportcard.com/badge/github.com/idevelopthings/surrealdb.go.unofficial\"/\u003e\n    \u003c/a\u003e    \n    \u003ca align=\"center\" target=\"_blank\" href=\"https://pkg.go.dev/github.com/idevelopthings/surrealdb.go.unofficial\"\u003e\n        \u003cimg src=\"https://pkg.go.dev/badge/github.com/idevelopthings/surrealdb.go.unofficial.svg\" alt=\"Go Reference\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    Unofficial fork of the \u003ca href=\"https://github.com/surrealdb/surrealdb.go\" target=\"_blank\"\u003esurrealdb\u003c/a\u003e package\n\u003c/p\u003e\n\n\u003chr\u003e\n\n# Credit:\n\nA lot of the underlying package was written by people in the community on\nthe [original package](https://github.com/surrealdb/surrealdb.go)\n\nI just wanted to have my modified version easily accessible to my self, and maybe others. So I take no credits for that(\nhopefully no one sees me as ripping there work and understands)\n\n# Features:\n\n- Contains my system for a \"Query Resolver\" using generics\n- Has options for auto context setup/timeouts(it's a pain in the ass to pass these around in go)\n- A little easier to set up for server usage only\n- Has a global DB instance\n\n# Installation:\n\n```shell\ngo get github.com/idevelopthings/surrealdb.go.unofficial\n```\n\n# Examples:\n\n## Setup:\n\n```go\nimport (\n\"github.com/idevelopthings/surrealdb.go.unofficial\"\n\"github.com/idevelopthings/surrealdb.go.unofficial/config\"\n)\ndb, err := surrealdb.New(ctx, \u0026\u0026 Config.DbConfig{\nUrl:       \"ws://localhost:8000/rpc\",\nUsername:  \"root\",\nPassword:  \"root\",\nDatabase:  \"test\",\nNamespace: \"test\",\n// This will call db.signin() with the supplied credentials\nAutoLogin: true,\n// This will call db.use() with the supplied credentials\nAutoUse:   true,\n// When using surrealdb.Query[MyModel](), timeouts will be configured\nTimeouts:  \u0026Config.DbTimeoutConfig{Timeout: time.Duration(10) * time.Second},\n})\n```\n\n# Query Resolver/Generics\n\n## Quick Overview:\n\nA lot of the query resolver use a similar interface/resolver setup\n\nThese methods exist on pretty much all resolver responses:\n\n```go\nresult.HasError() // Check if there was an error\nresult.Error()     // Get the go error if there is one\nresult.First()     // If you expect only 1 user object for example, it will take the first out of the response and return it(so you don't have to play with arrays, it will be a \"User\" instance for example)\nresult.All()     // Get all the results(an array of Users)\nresult.Results() // Get the raw surreal response/results\nresult.IsEmpty() // Check if there is any items in the result\n```\n\n**In some cases, for example, create, since only one record is ever expected(as we can only create one)**\n\nIt will use a ``.Item()`` method instead of ``.First()``, and will not contain ``.All()``\n\n## Query\n\nRun a query with parameters(parameters should be used to prevent injection)\n\n```go\nresult := surrealdb.Query[User](\"select * from users where name = $name\", map[string]any{\n\"name\": \"bob\",\n})\n\nresult.HasError() // Check if there was an error\nresult.Error()            // Get the go error if there is one\nresult.AllAreSuccessful() // Check if all queries were successful\nresult.TotalTimeTaken() // Calculate the total time of all queries\nresult.FirstQueryResult() // Get the first query result(surreal returns multiple results for a query, so if you run more than 1, this is useful)\nresult.First()            // If you expect only 1 user object for example, it will take the first out of the response and return it(so you don't have to play with arrays, it will be a \"User\" instance for example)\nresult.All()     // Get all the results(an array of Users)\nresult.Results() // Get the raw surreal response/results\n```\n\n## Select\n\nSelect one or many records\n\nIf an id is supplied for the first arg, it will select the one record with that id\nOtherwise, it expects a table name, where it will then select all records from that table.\n\n```go\n// Select one:\nresult := surrealdb.Select[User](\"user:12345\")\n// Select all:\nresult := surrealdb.Select[User](\"user\")\n\n// Refer to the above overview for the methods available on the result\n```\n\n## Create\n\nCreate one record\n\n```go\n// We can pass a map[string]any as the value\nsurrealdb.Create[User](\"user\", map[string]any {\"username\": \"Bob\"})\n// Or a struct:\nsurrealdb.Create[User](\"user\", User{Username: \"Bob\"})\n// Refer to the above overview for the methods available on the result\n```\n\n## Update\n\nUpdate one or many records\n\nIf an id is supplied for the first arg, it will update the one record with that id\nOtherwise, it expects a table name, where it will then update all records from that table.\n\nThis method will overwrite the entire record, if you want to update only a few fields, use the ``.Change()`` method\n\n```go\n// We can pass a map[string]any as the value\nsurrealdb.Update[User](\"user:12345\", map[string]any {\"username\": \"Bob\"})\n// Or a struct:\nsurrealdb.Update[User](\"user:12345\", User{Username: \"Bob\"})\n// Refer to the above overview for the methods available on the result\n```\n\n## Change\n\nUpdate one or many records, but will use a MERGE operation, so it will only update the fields you specify\n\nIf an id is supplied for the first arg, it will update the one record with that id\nOtherwise, it expects a table name, where it will then update all records from that table.\n\n```go\n// We can pass a map[string]any as the value\nsurrealdb.Change[User](\"user:12345\", map[string]any {\"username\": \"Bob\"})\n// Or a struct:\nsurrealdb.Change[User](\"user:12345\", User{Username: \"Bob\"})\n// Refer to the above overview for the methods available on the result\n```\n\n## Delete\n\nDelete one record, or all records in a table\n\nIf an id is supplied for the first arg, it will delete the one record with that id\nOtherwise, it expects a table name, where it will then delete all records from that table.\n\n```go\n// We can pass a map[string]any as the value\nsurrealdb.Delete[User](\"user:12345\")\n// Or a struct:\nsurrealdb.Delete[User](\"user:12345\")\n// Refer to the above overview for the methods available on the result\n```\n\n# WIP Query Builder\n\nExample:\n\n```go \nquery := surrealdb.NewBuilder[User](\"user\").\n    Where(\"username\", \"bob\")\n\nqueryResult := query.First() // = *User{Username: \"bob\"}\n```\n\n`query` contains some \"proxy\" methods that the QueryResolvers above also have\n\nSo if you keep a reference to it, it can be used to check if there was an error and such.\n\nFor example, with the above\n\n```go\nquery := surrealdb.NewBuilder[User](\"user\").\nWhere(\"username\", \"bob\")\nuser := query.First()\n\nif query.HasError() {\nlog.Fatal(query.Error())\n}\nif query.IsEmpty() {\nlog.Fatal(\"No user found\")\n}\n// Do something with user\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Fsurrealdb.go.unofficial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidevelopthings%2Fsurrealdb.go.unofficial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidevelopthings%2Fsurrealdb.go.unofficial/lists"}