A SQLite database.
The implementation uses a connection pool and is fully asynchronous. Each connection will be spawned in a worker thread.
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');");new Database():
Database
exec(
sql:string):Promise<void>
This method allows one or more SQL statements to be executed without returning any results.
| Parameter | Type |
|---|---|
sql |
string |
Promise<void>
prepare(
sql:string):Promise<Statement>
Compiles a SQL statement into a prepared statement.
| Parameter | Type |
|---|---|
sql |
string |
Promise<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.
new Statement():
Statement
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 Parameter | Default type |
|---|---|
T extends object |
object |
| Parameter | Type | Description |
|---|---|---|
...params |
Parameter[] |
The values to bind to the prepared statement. Named parameters are not supported. |
Promise<T[]>
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 Parameter | Default type |
|---|---|
T extends object |
object |
| Parameter | Type | Description |
|---|---|---|
...params |
Parameter[] |
The values to bind to the prepared statement. Named parameters are not supported. |
Promise<T | undefined>
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.
| Parameter | Type | Description |
|---|---|---|
...params |
Parameter[] |
The values to bind to the prepared statement. Named parameters are not supported. |
Promise<Result>
AnyFn = (...
args:any[]) =>MaybePromise<any>
| Parameter | Type |
|---|---|
...args |
any[] |
MaybePromise<any>
AnyVoidFn = (...
args:any[]) =>MaybePromise<void>
| Parameter | Type |
|---|---|
...args |
any[] |
MaybePromise<void>
APICallback<
T> =TextendsAnyFn? (sdk:SDK, ...args:Parameters<T>) =>ReturnType<T> :InvalidCallbackMessage
| Type Parameter |
|---|
T |
Console =
object
Console interface for logging.
Currently logs are only available in the backend logs. See the documentation on how to retrieve them.
debug(
message:any):void
Log a message with the debug level.
Usually used for troubleshooting purposes.
| Parameter | Type |
|---|---|
message |
any |
void
error(
message:any):void
Log a message with the error level.
Usually used for critical errors.
| Parameter | Type |
|---|---|
message |
any |
void
log(
message:any):void
Log a message with the info level.
Usually used for general information.
| Parameter | Type |
|---|---|
message |
any |
void
warn(
message:any):void
Log a message with the warn level.
Usually used for unexpected behaviors.
| Parameter | Type |
|---|---|
message |
any |
void
CreateEnvironmentInput =
object
name:
string
The name of the environment.
variables:
EnvironmentVariable[]
The variables of the environment.
EnvironmentVariableInput =
object
name:
string
The name of the environment variable.
secret:
boolean
If the environment variable should be treated as secret.
value:
string
The value of the environment variable.
EventParameters<
T> =TextendsAnyVoidFn?A:InvalidEventParametersMessage
| Type Parameter |
|---|
T |
ExactPluginPackageKeys<
T> = keyofTextendsPluginPackageSpecKey?PluginPackageSpecKeyextends keyofT?unknown:PluginPackageSpecKeyError:PluginPackageSpecKeyError
| Type Parameter |
|---|
T |
InvalidCallbackMessage =
"Your callback must respect the format (sdk: SDK, ...args: unknown[]) => MaybePromise<unknown>"
InvalidEventParametersMessage =
"Invalid event parameters"
MaybePromise<
T> =T|Promise<T>
| Type Parameter |
|---|
T |
PageInfo =
object
Information on the current page of paginated data.
endCursor:
Cursor
hasNextPage:
boolean
hasPreviousPage:
boolean
startCursor:
Cursor
Parameter =
null|number|bigint|string|Uint8Array
PluginPackageSpec =
object
api:
Record<string,AnyFn>
events:
Record<string,AnyVoidFn>
manifestId:
string
PluginPackageSpecKey = keyof
PluginPackageSpec
PluginPackageSpecKeyError =
"Only manifestId, api and events keys are allowed"
ResolvedAPI<
T> =Textendsobject?A:T
| Type Parameter |
|---|
T |
ResolvedEvents<
T,Events> =Textendsobject?A:Events
| Type Parameter |
|---|
T |
Events |
Result =
object
changes:
number
lastInsertRowid:
number
UpdateEnvironmentInput =
object
optionalname:string
The name of the environment.
optionalvariables:EnvironmentVariableInput[]
The variables of the environment.
version:
number
The version of the environment to update. If not equal to the current version, the update will fail.