Skip to content

Latest commit

Β 

History

History
499 lines (276 loc) Β· 8.92 KB

File metadata and controls

499 lines (276 loc) Β· 8.92 KB

Other

Database

A SQLite database.

The implementation uses a connection pool and is fully asynchronous. Each connection will be spawned in a worker thread.

Example

const db = await open({ filename: "path/to/database.sqlite" });
await db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT);");
await db.exec("INSERT INTO test (name) VALUES ('foo');");

Constructors

Constructor

new Database(): Database

Returns

Database

Methods

exec()

exec(sql: string): Promise<void>

This method allows one or more SQL statements to be executed without returning any results.

Parameters
Parameter Type
sql string
Returns

Promise<void>

prepare()

prepare(sql: string): Promise<Statement>

Compiles a SQL statement into a prepared statement.

Parameters
Parameter Type
sql string
Returns

Promise<Statement>


Statement

This class represents a single prepared statement. This class cannot be instantiated via its constructor. Instead, instances are created via the database.prepare() method.

Constructors

Constructor

new Statement(): Statement

Returns

Statement

Methods

all()

all<T>(...params: Parameter[]): Promise<T[]>

This method executes a prepared statement and returns all results as an array of objects. If the prepared statement does not return any results, this method returns an empty array. The prepared statement parameters are bound using the values in params.

Type Parameters
Type Parameter Default type
T extends object object
Parameters
Parameter Type Description
...params Parameter[] The values to bind to the prepared statement. Named parameters are not supported.
Returns

Promise<T[]>

get()

get<T>(...params: Parameter[]): Promise<T | undefined>

This method executes a prepared statement and returns the first result as an object. If the prepared statement does not return any results, this method returns undefined. The prepared statement parameters are bound using the values in params.

Type Parameters
Type Parameter Default type
T extends object object
Parameters
Parameter Type Description
...params Parameter[] The values to bind to the prepared statement. Named parameters are not supported.
Returns

Promise<T | undefined>

run()

run(...params: Parameter[]): Promise<Result>

This method executes a prepared statement and returns an object summarizing the resulting changes. The prepared statement parameters are bound using the values in params.

Parameters
Parameter Type Description
...params Parameter[] The values to bind to the prepared statement. Named parameters are not supported.
Returns

Promise<Result>


AnyFn()

AnyFn = (...args: any[]) => MaybePromise<any>

Parameters

Parameter Type
...args any[]

Returns

MaybePromise<any>


AnyVoidFn()

AnyVoidFn = (...args: any[]) => MaybePromise<void>

Parameters

Parameter Type
...args any[]

Returns

MaybePromise<void>


APICallback

APICallback<T> = T extends AnyFn ? (sdk: SDK, ...args: Parameters<T>) => ReturnType<T> : InvalidCallbackMessage

Type Parameters

Type Parameter
T

Console

Console = object

Console interface for logging.

Currently logs are only available in the backend logs. See the documentation on how to retrieve them.

Methods

debug()

debug(message: any): void

Log a message with the debug level.

Usually used for troubleshooting purposes.

Parameters
Parameter Type
message any
Returns

void

error()

error(message: any): void

Log a message with the error level.

Usually used for critical errors.

Parameters
Parameter Type
message any
Returns

void

log()

log(message: any): void

Log a message with the info level.

Usually used for general information.

Parameters
Parameter Type
message any
Returns

void

warn()

warn(message: any): void

Log a message with the warn level.

Usually used for unexpected behaviors.

Parameters
Parameter Type
message any
Returns

void


CreateEnvironmentInput

CreateEnvironmentInput = object

Properties

name

name: string

The name of the environment.

variables

variables: EnvironmentVariable[]

The variables of the environment.


EnvironmentVariableInput

EnvironmentVariableInput = object

Properties

name

name: string

The name of the environment variable.

secret

secret: boolean

If the environment variable should be treated as secret.

value

value: string

The value of the environment variable.


EventParameters

EventParameters<T> = T extends AnyVoidFn ? A : InvalidEventParametersMessage

Type Parameters

Type Parameter
T

ExactPluginPackageKeys

ExactPluginPackageKeys<T> = keyof T extends PluginPackageSpecKey ? PluginPackageSpecKey extends keyof T ? unknown : PluginPackageSpecKeyError : PluginPackageSpecKeyError

Type Parameters

Type Parameter
T

InvalidCallbackMessage

InvalidCallbackMessage = "Your callback must respect the format (sdk: SDK, ...args: unknown[]) => MaybePromise<unknown>"


InvalidEventParametersMessage

InvalidEventParametersMessage = "Invalid event parameters"


MaybePromise

MaybePromise<T> = T | Promise<T>

Type Parameters

Type Parameter
T

PageInfo

PageInfo = object

Information on the current page of paginated data.

Properties

endCursor

endCursor: Cursor

hasNextPage

hasNextPage: boolean

hasPreviousPage

hasPreviousPage: boolean

startCursor

startCursor: Cursor


Parameter

Parameter = null | number | bigint | string | Uint8Array


PluginPackageSpec

PluginPackageSpec = object

Properties

api

api: Record<string, AnyFn>

events

events: Record<string, AnyVoidFn>

manifestId

manifestId: string


PluginPackageSpecKey

PluginPackageSpecKey = keyof PluginPackageSpec


PluginPackageSpecKeyError

PluginPackageSpecKeyError = "Only manifestId, api and events keys are allowed"


ResolvedAPI

ResolvedAPI<T> = T extends object ? A : T

Type Parameters

Type Parameter
T

ResolvedEvents

ResolvedEvents<T, Events> = T extends object ? A : Events

Type Parameters

Type Parameter
T
Events

Result

Result = object

Properties

changes

changes: number

lastInsertRowid

lastInsertRowid: number


UpdateEnvironmentInput

UpdateEnvironmentInput = object

Properties

name?

optional name: string

The name of the environment.

variables?

optional variables: EnvironmentVariableInput[]

The variables of the environment.

version

version: number

The version of the environment to update. If not equal to the current version, the update will fail.