Skip to main content
Module

x/surrealdb/mod.ts>default

SurrealDB driver for JavaScript
Go to Latest
class default
import { default } from "https://deno.land/x/surrealdb@v1.0.0-beta.2/mod.ts";

Constructors

new
default(unnamed 0?: { engines?: Engines; })

Properties

private
optional
pinger: Pinger
protected
engines: Engines
connection: Engine | undefined
emitter: Emitter<EngineEvents>
optional
ready: Promise<void>
readonly
status

Check if connection is ready

Methods

private
clean()
protected
rpc<Result extends unknown>(method: string, params?: unknown[])

Send a raw message to the SurrealDB instance

Authenticates the current connection with a JWT token.

Disconnect the socket to the database

connect(url: string | URL, opts?: ConnectionOptions)

Establish a socket connection to the database

create<T extends R, U extends R = T>(thing: string, data?: U): Promise<ActionResult<T>[]>

Creates a record in the database.

create<T extends R, U extends R = T>(thing: RecordId, data?: U): Promise<ActionResult<T>>
delete<T extends R>(thing: string): Promise<ActionResult<T>[]>

Deletes all records in a table, or a specific record, from the database.

delete<T extends R>(thing: RecordId): Promise<ActionResult<T>>
info<T extends Record<string, unknown> = Record<string, unknown>>()

Selects everything from the $auth variable.

SELECT * FROM $auth;

Make sure the user actually has the permission to select their own record, otherwise you'll get back an empty result.

insert<T extends R, U extends R = T>(thing: string, data?: U | U[]): Promise<ActionResult<T>[]>

Inserts one or multiple records in the database.

insert<T extends R, U extends R = T>(thing: RecordId, data?: U): Promise<ActionResult<T>>

Invalidates the authentication for the current connection.

kill(queryUuid: string | string[])

Kill a live query

let(variable: string, value: unknown)

Specify a variable for the current socket connection.

live<Result extends Record<string, unknown> | Patch = Record<string, unknown>>(
table: string,
callback?: LiveHandler<Result>,
diff?: boolean,
)

Start a live query and listen for the responses

merge<T extends R, U extends R = Partial<T>>(thing: string, data?: U): Promise<ActionResult<T>[]>

Modifies all records in a table, or a specific record, in the database.

NOTE: This function merges the current document / record data with the specified data.

merge<T extends R, U extends R = Partial<T>>(thing: RecordId, data?: U): Promise<ActionResult<T>>
patch<T extends R>(
thing: RecordId,
data?: Patch[],
diff?: false,
): Promise<ActionResult<T>>

Applies JSON Patch changes to all records, or a specific record, in the database.

NOTE: This function patches the current document / record data with the specified JSON Patch data.

patch<T extends R>(
thing: string,
data?: Patch[],
diff?: false,
): Promise<ActionResult<T>[]>
patch<T extends R>(
thing: RecordId,
data: undefined | Patch[],
diff: true,
): Promise<Patch[]>
patch<T extends R>(
thing: string,
data: undefined | Patch[],
diff: true,
): Promise<Patch[][]>

Ping SurrealDB instance

query<T extends unknown[]>(query: string | PreparedQuery, bindings?: Record<string, unknown>)

Runs a set of SurrealQL statements against the database.

query_raw<T extends unknown[]>(query: string | PreparedQuery, bindings?: Record<string, unknown>)

Runs a set of SurrealQL statements against the database.

select<T extends R>(thing: string): Promise<ActionResult<T>[]>

Selects all records in a table, or a specific record, from the database.

select<T extends R>(thing: RecordId): Promise<ActionResult<T>>

Signs in to a specific authentication scope.

Signs up to a specific authentication scope.

subscribeLive<Result extends Record<string, unknown> | Patch = Record<string, unknown>>(queryUuid: string, callback: LiveHandler<Result>)

Listen for live query responses by it's uuid

unset(variable: string)

Remove a variable from the current socket connection.

unSubscribeLive<Result extends Record<string, unknown> | Patch = Record<string, unknown>>(queryUuid: string, callback: LiveHandler<Result>)

Listen for live query responses by it's uuid

update<T extends R, U extends R = T>(thing: string, data?: U): Promise<ActionResult<T>[]>

Updates all records in a table, or a specific record, in the database.

NOTE: This function replaces the current document / record data with the specified data.

update<T extends R, U extends R = T>(thing: RecordId, data?: U): Promise<ActionResult<T>>
use(unnamed 0: { namespace?: string; database?: string; })

Switch to a specific namespace and database.

Constructors

new
default(unnamed 0?: { engines?: Engines; })

Properties

private
optional
pinger: Pinger
protected
engines: Engines
connection: Engine | undefined
emitter: Emitter<EngineEvents>
optional
ready: Promise<void>
readonly
status

Check if connection is ready

Methods

private
clean()
protected
rpc<Result extends unknown>(method: string, params?: unknown[])

Send a raw message to the SurrealDB instance

Authenticates the current connection with a JWT token.

Disconnect the socket to the database

connect(url: string | URL, opts?: ConnectionOptions)

Establish a socket connection to the database

create<T extends R, U extends R = T>(thing: string, data?: U): Promise<ActionResult<T>[]>

Creates a record in the database.

create<T extends R, U extends R = T>(thing: RecordId, data?: U): Promise<ActionResult<T>>
delete<T extends R>(thing: string): Promise<ActionResult<T>[]>

Deletes all records in a table, or a specific record, from the database.

delete<T extends R>(thing: RecordId): Promise<ActionResult<T>>
info<T extends Record<string, unknown> = Record<string, unknown>>()

Selects everything from the $auth variable.

SELECT * FROM $auth;

Make sure the user actually has the permission to select their own record, otherwise you'll get back an empty result.

insert<T extends R, U extends R = T>(thing: string, data?: U | U[]): Promise<ActionResult<T>[]>

Inserts one or multiple records in the database.

insert<T extends R, U extends R = T>(thing: RecordId, data?: U): Promise<ActionResult<T>>

Invalidates the authentication for the current connection.

kill(queryUuid: string | string[])

Kill a live query

let(variable: string, value: unknown)

Specify a variable for the current socket connection.

live<Result extends Record<string, unknown> | Patch = Record<string, unknown>>(
table: string,
callback?: LiveHandler<Result>,
diff?: boolean,
)

Start a live query and listen for the responses

merge<T extends R, U extends R = Partial<T>>(thing: string, data?: U): Promise<ActionResult<T>[]>

Modifies all records in a table, or a specific record, in the database.

NOTE: This function merges the current document / record data with the specified data.

merge<T extends R, U extends R = Partial<T>>(thing: RecordId, data?: U): Promise<ActionResult<T>>
patch<T extends R>(
thing: RecordId,
data?: Patch[],
diff?: false,
): Promise<ActionResult<T>>

Applies JSON Patch changes to all records, or a specific record, in the database.

NOTE: This function patches the current document / record data with the specified JSON Patch data.

patch<T extends R>(
thing: string,
data?: Patch[],
diff?: false,
): Promise<ActionResult<T>[]>
patch<T extends R>(
thing: RecordId,
data: undefined | Patch[],
diff: true,
): Promise<Patch[]>
patch<T extends R>(
thing: string,
data: undefined | Patch[],
diff: true,
): Promise<Patch[][]>

Ping SurrealDB instance

query<T extends unknown[]>(query: string | PreparedQuery, bindings?: Record<string, unknown>)

Runs a set of SurrealQL statements against the database.

query_raw<T extends unknown[]>(query: string | PreparedQuery, bindings?: Record<string, unknown>)

Runs a set of SurrealQL statements against the database.

select<T extends R>(thing: string): Promise<ActionResult<T>[]>

Selects all records in a table, or a specific record, from the database.

select<T extends R>(thing: RecordId): Promise<ActionResult<T>>

Signs in to a specific authentication scope.

Signs up to a specific authentication scope.

subscribeLive<Result extends Record<string, unknown> | Patch = Record<string, unknown>>(queryUuid: string, callback: LiveHandler<Result>)

Listen for live query responses by it's uuid

unset(variable: string)

Remove a variable from the current socket connection.

unSubscribeLive<Result extends Record<string, unknown> | Patch = Record<string, unknown>>(queryUuid: string, callback: LiveHandler<Result>)

Listen for live query responses by it's uuid

update<T extends R, U extends R = T>(thing: string, data?: U): Promise<ActionResult<T>[]>

Updates all records in a table, or a specific record, in the database.

NOTE: This function replaces the current document / record data with the specified data.

update<T extends R, U extends R = T>(thing: RecordId, data?: U): Promise<ActionResult<T>>
use(unnamed 0: { namespace?: string; database?: string; })

Switch to a specific namespace and database.