SurrealDB Docs Logo

Enter a search query

SDK methods

The SurrealDB SDK for JavaScript 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 JavaScript or SurrealDB. This page lists out the methods that are available in the SurrealDB class.

Initialization methods

MethodDescription
db.connect(url, options)Connects to a local or remote database endpoint
db.close()Closes the persistent connection to the database
db.use(namespace,database)Switch to a specific namespace and database
db.let(key,val)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,vars)Runs a set of SurrealQL statements against the database
db.select<T>(thing)Selects all records in a table, or a specific record
async db.live<T>(table, callback,diff)Initiate a live query
async db.subscribeLive<T>(queryUuid,callback)Register a callback for a running live query
async db.kill(queryUuid)Kill a running live query

Mutation methods

MethodDescription
db.create<T,U>(thing,data)Creates a record in the database
db.insert<T,U>(thing,data)Inserts one or multiple records in the database
db.update<T,U>(thing,data)Updates all records in a table, or a specific record
db.merge<T,U>(thing,data)Modifies all records in a table, or a specific record
db.patch<T,U>(thing,data)Applies JSON Patch changes to all records in a table, or a specific record
db.delete<T,U>(thing,data)Deletes all records, or a specific record

Authentication methods

MethodDescription
db.signup(vars)Signs this connection up to a specific authentication scope
db.signin(vars)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