Skip to content

Database class

Home > @direct-sqlite/core > Database

High-performance, zero-allocation abstraction layer for SQLite instances. Normalizes differences between better-sqlite3, node:sqlite and ‘bun:sqlite`.

Signature:

export declare class Database

Constructor

Modifiers

Description

(constructor)(client, options)

Constructs a new instance of the Database class

Property

Modifiers

Type

Description

client

readonly

GenericSqliteClient

Method

Modifiers

Description

aggregate(name, options)

Hooks up custom metric calculations that aggregate state step-by-step across matching rows.

backup(destinationPath)

Performs a non-blocking copy of the database to target path.

checkpoint()

Flushes tracked log buffers back into primary storage to shrink log file.

createTable(tableConfig)

Creates a table based on the provided configuration and returns a TableRunner for that table.

function(name, callback)

Binds a custom JavaScript runtime algorithm which is directly executable in SQL queries.

getStatement(sql)

Resolves statements from cache or registers a fresh pointer with LRU cache eviction defenses active.

optimize(mode)

Fine tunes the database engine for high-throughput scenarios.

table(tableConfig)

Initializes a TableRunner for an existing table in the database, allowing for fluent query building and execution.

transaction(callback)

Executes a series of database operations within a transaction. If any operation throws an error, the transaction will be rolled back.