SurrealDB Docs Logo

Enter a search query

SDK methods

The Golang SDK for SurrealDB has a single SurrealDB class that provides methods for querying a remote SurrealDB database.

The class is designed to be simple to use and easy to understand for developers who are new to Golang or SurrealDB.

This page lists out the methods that are available in the SurrealDB class.

Initialization methods

MethodDescription
db.New()Connects the client to the underlying endpoint, also improving performance to avoid cold starts
db.Use(namespace, database)Switch to a specific namespace and database
db.Let(key, value)Assigns a value as a parameter for this connection
db.Unset(key)Removes a parameter for this connection

Query methods

MethodDescription
db.Query[T](sql string, vars …interface)Runs a set of SurrealQL statements against the database
db.RawQuery[T](sql, vars)Runs a set of SurrealQL statements against the database, based on a raw SurrealQL query
db.Select[T,R](resource)Selects all records in a table, or a specific record
db.Live[T](table, diff)Initiate a live query from a SurrealQL statement
db.LiveNotifications[T](queryUuid)Get notifications from a live query
db.Kill(queryUuid)Kill a running live query

Mutation methods

MethodDescription
db.Create[T](table, data)Creates a record in the database
db.Insert[T](table, data)Inserts one or multiple records in the database
db.InsertRelation[T](table, data)Inserts one or multiple records in the database
db.Update[T](table, data)Updates all records in a table, or a specific record
db.Upsert[T](table, data)Creates or updates a specific record
db.Merge[T](what, data)Modifies all records in a table, or a specific record
db.Patch[T](table, data)Applies JSON Patch changes to all records in a table, or a specific record
db.Delete(data)Deletes all records, or a specific record

Authentication methods

MethodDescription
db.SignUp(credentials)Signs this connection up to a specific authentication scope
db.SignIn(credentials)Signs this connection in to a specific authentication scope
db.Invalidate()Invalidates the authentication for the current connection
db.Authenticate(token)Authenticates the current connection with a JWT token
db.Info[T]()Returns the record of an authenticated scope user

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install