Skip to main content
Module

x/surrealdb/mod.ts>Surreal

SurrealDB driver for JavaScript
Go to Latest
class Surreal
extends Emitter<SurrealBaseEventMap & [K in Exclude<EventName, keyof SurrealBaseEventMap>]: [Result<any>]>
import { Surreal } from "https://deno.land/x/surrealdb@v0.6.0/mod.ts";

Constructors

new
Surreal(url?: string, token?: string)

Initializee a SurrealDb.

Properties

token: string | undefined

Methods

authenticate(token: string): Promise<void>

Authenticates the current connection with a JWT token.

change<T extends Record<string, unknown>, U extends Record<string, unknown> = T, RID extends string | void = void>(thing: Exclude<RID, void>, data?: Partial<T> & U): Promise<ReturnsThing<T & U & { id: string; }, Exclude<RID, void>>>

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.

close(): void

Closes the persistent connection to the database.

connect(url: string): Promise<void>

Connects to a local or remote database endpoint.

create<T extends Record<string, unknown>>(thing: string, data?: T): Promise<T & { id: Thing; }>

Creates a record in the database.

delete(thing: string): Promise<void>

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

info(): Promise<void>

Retreive info about the current Surreal instance

invalidate(): Promise<void>

Invalidates the authentication for the current connection.

kill(query: string): Promise<void>

Kill a specific query.

let(key: string, val: unknown): Promise<string>

Switch to a specific namespace and database.

live(table: string): Promise<string>
modify<RID extends string>(thing: RID, data?: Patch[]): Promise<ReturnsThing<Patch, RID>>

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.

ping(): Promise<void>

Ping SurrealDB instance

query<T>(query: string, vars?: Record<string, unknown>): Promise<Result<T>[]>

Runs a set of SurrealQL statements against the database.

select<T, RID extends string>(thing: RID): Promise<ReturnsThing<T, RID>>

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

signin(vars: Auth): Promise<string>

Signs in to a specific authentication scope.

signup(vars: ScopeAuth): Promise<string>

Signs up to a specific authentication scope.

sync(query: string, vars?: Record<string, unknown>): Live
update<T extends Record<string, unknown>, RID extends string>(thing: RID, data?: T): Promise<ReturnsThing<T & { id: Thing; }, RID>>

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.

use(ns: string, db: string): Promise<void>

Switch to a specific namespace and database.

wait(): Promise<void>

Waits for the connection to the database to succeed.

Static Properties

readonly
AuthenticationError: AuthenticationError
readonly
Instance: Surreal

The Instance static singleton ensures that a single database instance is available across very large or complicated applications. With the singleton, only one connection to the database is instantiated, and the database connection does not have to be shared across components or controllers.

readonly
Live: Live
readonly
PermissionError: PermissionError
readonly
RecordError: RecordError