Types
The Go SDK defines several types used by the client methods and data manipulation functions. These types are defined in the main surrealdb package and the pkg/connection package.
Package: github.com/surrealdb/surrealdb.go
Source: types.go
Authentication
Auth
Holds authentication credentials for signing in. The fields you populate determine the authentication level.
| Field | JSON key | When to use |
|---|---|---|
Namespace | NS | Namespace-level, database-level, or record-level signin |
Database | DB | Database-level or record-level signin |
Scope | SC | Legacy scope-based signin (SurrealDB v1.x) |
Access | AC | Record-level signin via a defined access method |
Username | user | All signin levels |
Password | pass | All signin levels |
You can also use map[string]any with the JSON keys directly, which allows passing additional fields required by access methods.
Tokens
Contains access and refresh tokens returned by .SignInWithRefresh() and .SignUpWithRefresh(). Only available with TYPE RECORD access methods that have WITH REFRESH enabled (SurrealDB v3+).
| Field | Description |
|---|---|
Access | JWT token for authentication. Use with .Authenticate(). |
Refresh | Refresh token (format: surreal-refresh-...). Use with .SignInWithRefresh() to obtain new tokens. |
Query Results
QueryResult
Represents one statement's result from a Query call. The type parameter T corresponds to the expected result type.
| Field | Description |
|---|---|
Status | "OK" for success, "ERR" for failure |
Time | Execution time for this statement |
Result | The typed result data |
Error | Non-nil when the statement failed. See QueryError. |
QueryStmt
Represents a single query statement for use with QueryRaw. After execution, the Result field is populated and .GetResult() can unmarshal it into a destination type.
Methods
.GetResult(dest any) error— unmarshals the raw result intodest
Data Types
PatchData
Represents a single JSON Patch operation for use with the Patch function.
Supported Op values: add, remove, replace, move, copy, test.
Relationship
Represents a graph edge between two records. Used with Relate and InsertRelation.
| Field | Type | Description |
|---|---|---|
ID | *models.RecordID | The relation record ID. Auto-generated by Relate, optional for InsertRelation. |
In | models.RecordID | The source record. |
Out | models.RecordID | The target record. |
Relation | models.Table | The relation table name. |
Data | map[string]any | Additional data to store on the relation. |
VersionData
Contains version information returned by .Version().
Notification
Represents a live query notification received through a notification channel.
Package: github.com/surrealdb/surrealdb.go/pkg/connection
| Field | Type | Description |
|---|---|---|
ID | *models.UUID | The live query UUID |
Action | Action | One of CREATE, UPDATE, or DELETE |
Result | any | The record data or JSON Patch diff |
Type Constraints
TableOrRecord
A type constraint used by data manipulation functions. Accepts any of the following types:
See Table and RecordID for these value types.
sendable
A type constraint for types that can execute RPC requests. Satisfied by *DB, *Session, and *Transaction.
liveQueryable
A type constraint for types that support live queries. Satisfied by *DB and *Session (not *Transaction).
See Also
DB reference for methods that use these types
Errors reference for error types
Values reference for value types like
RecordIDandTable