The .NET 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 .NET or SurrealDB. This page lists out the methods that are available in the SurrealDB class.
Initialisation methods
Method | Description |
|---|---|
db.Connect() | 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.Set(key, value) | Assigns a value as a parameter for this connection |
db.Unset(key) | Removes a parameter for this connection |
db.Health() | Checks the status of the database server and storage engine |
db.Version() | Retrieves the version of the SurrealDB instance |
Query methods
Method | Description |
|---|---|
db.Query<T>(sql) | 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>(thing) | Selects all records in a table, or a specific record |
db.LiveQuery<T>(sql) | Initiate a live query from a SurrealQL statement |
db.LiveRawQuery<T>(sql) | Initiate a live query from a SurrealQL statement, based on a raw SurrealQL query |
db.LiveTable<T>(table, diff) | Initiate a live query from a table |
db.ListenLive<T>(queryUuid) | Listen responses from an existing live query |
db.Kill(queryUuid) | Kill a running live query |
db.Run(name, version, args) | Runs a SurrealQL function |
Mutation methods
Method | Description |
|---|---|
db.Create<T>(thing, data) | Creates a record in the database |
db.Insert<T>(thing, data) | Inserts one or multiple records in the database |
db.Update<T>(thing, data) | Updates all records in a table, or a specific record |
db.Upsert<T>(thing, data) | Creates or updates a specific record |
db.Merge<T>(thing, data) | Modifies all records in a table, or a specific record |
db.Patch<T>(thing, data) | Applies JSON Patch changes to all records in a table, or a specific record |
db.Delete(thing) | Deletes all records, or a specific record |
db.Relate(table, @in, @out, data) | Creates a graph relation between two records |
db.InsertRelation<T>(table, data) | Inserts one or more graph relations into a table |
Live query methods
A live query streams changes as they happen. Start one from a statement or a table, listen to the stream it returns, then stop it with the query's id.
Method | Description |
|---|---|
db.LiveQuery<T>(sql) | Initiates a live query from a SurrealQL statement |
db.LiveRawQuery<T>(sql, params) | Initiates a live query from a raw SurrealQL statement with parameters |
db.LiveTable<T>(table, diff) | Initiates a live query on a whole table |
db.ListenLive<T>(queryUuid) | Listens for changes on a live query that is already running |
db.Kill(queryUuid) | Stops a running live query |
Data management methods
Method | Description |
|---|---|
db.Export(options) | Exports the database as a SurrealQL script |
db.Import(string) | Imports a SurrealQL script into the database |
Authentication methods
Method | Description |
|---|---|
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 |