Skip to main content

BaseSQLiteDatabase

The core SQLite database class that provides all query builder methods and transaction support.

Type Parameters

'sync' | 'async'
Determines whether the database operates in synchronous or asynchronous mode
any
The return type for run operations (typically contains lastInsertRowid and changes)
Record<string, unknown>
The full schema definition including all tables and relations

Methods

select()

Creates a select query. Call with no arguments to select all columns, or pass a selection object to specify columns.

selectDistinct()

Adds DISTINCT to the select query, returning only unique values.

insert()

Creates an insert query to add new rows to a table.

update()

Creates an update query to modify existing rows. Use .set() to specify values and .where() to filter rows.

delete()

Creates a delete query to remove rows from a table.

$with()

Creates a Common Table Expression (CTE) that can be referenced in subsequent queries.

with()

Incorporates previously defined CTEs into the main query.

$count()

Counts rows in a table or view with optional filtering.

run()

Executes a raw SQL query that doesn’t return data (e.g., DDL statements).

all()

Executes a query and returns all rows.

get()

Executes a query and returns the first row.

values()

Executes a query and returns rows as arrays of values.

transaction()

Executes a function within a database transaction.

withReplicas()

Configures a database instance to use read replicas for select queries.
BaseSQLiteDatabase
required
The primary database instance for write operations
BaseSQLiteDatabase[]
required
Array of replica database instances for read operations
(replicas: Q[]) => Q
Custom function to select a replica. Defaults to random selection