The SurrealDB SDK for Go lets you connect to SurrealDB from servers, command-line tools, APIs and other Go programs. It connects to a remote instance over WebSocket or HTTP and sends SurrealQL as CBOR.
Queries and record operations are generic functions, such as surrealdb.Query[T] and surrealdb.Select[T]. Each one decodes the result into the Go type that you give.
Use the SDK to run queries, read and write records, and sign users in. You can also keep their tokens fresh, receive changes with live queries, and group statements in interactive transactions.
The SDK requires Go 1.24 or later. It is available as a Go module, and its module path is github.com/surrealdb/surrealdb.go/v2.
The latest version of the SDK is v2.0.1. It works with SurrealDB 3.3 and later 3.x releases, and with SurrealDB 4.x. The current SurrealDB release is v4.0.1.
Before you upgrade a project from version 1 of the SDK, read Migrating to Go SDK 2.x. Version 2 changes the module path, the supported server versions, and how the SDK sends some Go values to the server.
Getting started
Learn
Concepts
Connecting to SurrealDB - open a connection over WebSocket or HTTP, with options and a version check
Authentication - sign up, sign in, and keep a token fresh
Executing queries - send SurrealQL, call functions and
DEFINE APIendpointsData manipulation - create, select, update, upsert, patch, relate and delete records
Live queries - receive changes as they happen
Error handling - what a failure looks like, and how to check it
Value types - how SurrealDB's types map onto Go ones
Multiple sessions - run isolated sessions over a single connection
Transactions - run statements one at a time, then commit or cancel
Reliable connections - reconnect automatically and restore the session
Query builder - build SurrealQL with bound parameters
Streaming results - read the records of a large query as they arrive
Import and export - back up and restore a database as SurrealQL
Contributing
To contribute to the SDK code, submit an Issue or Pull Request in the surrealdb.go repository. To contribute to this documentation, submit an Issue or Pull Request in the docs.surrealdb.com repository.