Skip to content

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

ts
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
ParameterType
sqlstring
Returns

Promise<void>

prepare()

prepare(sql: string): Promise<Statement>

Compiles a SQL statement into a prepared statement.

Parameters
ParameterType
sqlstring
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 ParameterDefault type
T extends objectobject
Parameters
ParameterTypeDescription
...paramsParameter[]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 ParameterDefault type
T extends objectobject
Parameters
ParameterTypeDescription
...paramsParameter[]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
ParameterTypeDescription
...paramsParameter[]The values to bind to the prepared statement. Named parameters are not supported.
Returns

Promise<Result>


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
ParameterType
messageany
Returns

void

error()

error(message: any): void

Log a message with the error level.

Usually used for critical errors.

Parameters
ParameterType
messageany
Returns

void

log()

log(message: any): void

Log a message with the info level.

Usually used for general information.

Parameters
ParameterType
messageany
Returns

void

warn()

warn(message: any): void

Log a message with the warn level.

Usually used for unexpected behaviors.

Parameters
ParameterType
messageany
Returns

void


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


RequestSendOptions

RequestSendOptions = object

Properties

save?

optional save: boolean

If true, the request and response will be saved to the database and the user will see them in the Search tab.

If you do not save, the request and response IDs will be set to 0.

Default
ts
true
timeouts?

optional timeouts: RequestSendTimeouts | number

The timeouts to use for sending a request and receiving a response.

If a number is provided, it will be used as the global timeout and the other timeouts will be set to infinity.

See the RequestSendTimeouts for the default values.


Result

Result = object

Properties

changes

changes: number

lastInsertRowid

lastInsertRowid: number