webtessera/storage/sqlite

The SQLite backend and one adapter per engine.

It has no Go counterpart: it is an addition of webtessera’s. Its source is src/storage/sqlite/index.ts.

Functions

fromD1
fromD1 adapts a Cloudflare D1 database binding to the SqlDatabase the SQLite ObjectStore runs on: const driver = await newSqliteDriver({ database: fromD1(env.DB) }); A D1 database is reached from every isolate of every Worker bound to it, so stores default to "lease" locking, timed by the database's clock: every statement runs on the database's single primary, whose clock all contenders therefore share.
fromDurableObjectStorage
fromDurableObjectStorage adapts the storage of a SQLite-backed Durable Object, ctx.storage, to the SqlDatabase the SQLite ObjectStore runs on: const driver = await newSqliteDriver({ database: fromDurableObjectStorage(ctx.storage) }); The runtime runs at most one instance of a Durable Object at a time, and only that instance reaches its storage, so stores default to "local" locking.
fromLibsql
fromLibsql adapts a libSQL client to the SqlDatabase the SQLite ObjectStore runs on: const client = createClient({ url: "libsql://my-db.turso.io", authToken }); const driver = await newSqliteDriver({ database: fromLibsql(client) }); Locking fails closed.
fromRqlite
fromRqlite adapts an rqlite cluster to the SqlDatabase the SQLite ObjectStore runs on: const driver = await newSqliteDriver({ database: fromRqlite({ url: "http://localhost:4001" }) }); Every statement goes through rqlite's unified /db/request endpoint, and a batch as one transaction.
fromSqliteSync
fromSqliteSync adapts a synchronous SQLite connection, from node:sqlite, bun:sqlite or better-sqlite3, to the SqlDatabase the SQLite ObjectStore runs on: import { DatabaseSync } from "node:sqlite"; const driver = await newSqliteDriver({ database: fromSqliteSync(new DatabaseSync("log.db")) }); It raises the connection's synchronous setting to FULL if it is lower, so that every write has reached the disk when it resolves, and gives it a busy timeout if it has none.
fromSqliteWasm
fromSqliteWasm adapts a database opened with SQLite's WebAssembly build to the SqlDatabase the SQLite ObjectStore runs on: const sqlite3 = await sqlite3InitModule(); const driver = await newSqliteDriver({ database: fromSqliteWasm(new sqlite3.oo1.OpfsDb("/log.db")) }); Locking fails closed.
newSqliteDriver
newSqliteDriver opens a SQLite ObjectStore in cfg.database, as openSqliteObjectStore does, and returns a storage driver that keeps the log in it, for newAppender, newMigrationTarget and the like: const driver = await newSqliteDriver({ database: fromSqliteSync(new DatabaseSync("log.db")) }); signal bounds only the opening.
openSqliteObjectStore
openSqliteObjectStore returns an ObjectStore kept in opts.database, creating its tables if they do not exist and upgrading them if an earlier webtessera created them.

Interfaces

D1DatabaseLike
D1DatabaseLike is the part of D1's D1Database fromD1 uses.
D1PreparedStatementLike
D1PreparedStatementLike is the part of D1's D1PreparedStatement fromD1 uses.
DurableObjectSqlCursorLike
DurableObjectSqlCursorLike is the part of the runtime's SqlStorageCursor fromDurableObjectStorage uses.
DurableObjectSqlStorageLike
DurableObjectSqlStorageLike is the part of the runtime's SqlStorage (ctx.storage.sql) fromDurableObjectStorage uses.
DurableObjectStorageLike
DurableObjectStorageLike is the part of a Durable Object's storage, ctx.storage, fromDurableObjectStorage uses.
LibsqlClientLike
LibsqlClientLike is the part of libSQL's Client fromLibsql uses.
LibsqlResultSetLike
LibsqlResultSetLike is the part of libSQL's ResultSet fromLibsql reads.
LibsqlStatementLike
LibsqlStatementLike is the statement shape fromLibsql passes to the client.
RqliteOptions
RqliteOptions configures fromRqlite.
SqlDatabase
SqlDatabase is the minimal, engine-neutral interface the SQLite ObjectStore needs from a database.
SqliteDriverConfig
SqliteDriverConfig configures newSqliteDriver.
SqliteLeaseOptions
SqliteLeaseOptions tunes the leases behind "lease" locking.
SqliteObjectStore
SqliteObjectStore is an ObjectStore kept in SQLite tables.
SqliteObjectStoreOptions
SqliteObjectStoreOptions configures openSqliteObjectStore.
SqliteSyncDatabase
SqliteSyncDatabase is the part of a synchronous SQLite connection fromSqliteSync uses.
SqliteSyncStatement
SqliteSyncStatement is the part of a prepared statement fromSqliteSync uses: node:sqlite's StatementSync, bun:sqlite's Statement and better-sqlite3's Statement all have it.
SqliteWasmDatabaseLike
SqliteWasmDatabaseLike is the part of a sqlite3.oo1.DB fromSqliteWasm uses.
SqliteWasmExecOptions
SqliteWasmExecOptions is the form of exec options fromSqliteWasm uses.
SqlStatement
SqlStatement is one SQL statement and the values of its parameters.

Types

RqliteReadLevel
RqliteReadLevel is an rqlite read consistency level that always reads the latest committed data: "linearizable" confirms the node's leadership with a quorum before reading, and "strong" sends the read through the Raft log. rqlite's weaker levels are not offered: a stale read of the tree state, during a leadership change, would have the driver assign indices that are already taken.
SqliteLocking
SqliteLocking selects how a SQLite ObjectStore implements ObjectStore.lock. "lease" locks are rows in the database, held for a bounded time and renewed while held, so they exclude every connection, process, isolate or machine that reaches the database, and every write made while one is held is fenced on it still being held.
SqliteLockingOption
SqliteLockingOption is what a store's options accept for its locking: a SqliteLocking, or "single-writer", the same as "local" under a name that says what choosing it promises: that this realm is the database's only writer.
SqlRow
SqlRow is one row of a result, keyed by column name.
SqlValue
SqlValue is a value bound to, or read from, a SQL statement.

Constants and variables

DefaultMaxChunkBytes
DefaultMaxChunkBytes is the default for SqliteObjectStoreOptions.maxChunkBytes: 1 MiB.
ErrLeaseLost
ErrLeaseLost is the cause of every error a lease-mode SQLite ObjectStore reports for a write it refused because a lock lease the store held has lapsed and another holder may have taken it over.
ErrWriterConflict
ErrWriterConflict is the cause of every error a SQLite ObjectStore opened with locking: "single-writer" (or "local") reports once another realm, usually another process, has started writing the same database under the same declaration.
SchemaVersion
SchemaVersion is the version of the tables this code creates and expects.