Skip to content
LogoLogo

Store.sqlite

SQLite storage

Creates an atomic store from a SQLite database's prepared statements.

Usage

import {  } from 'mppx'
import {  } from 'node:sqlite'
 
const  = new ('mppx.db')
const  = .() 
 
await .('usage:customer-42', { : 1 })
.(await .('usage:customer-42'))
{ requests: 1 }

Supports node:sqlite, better-sqlite3, and bun:sqlite with SQLite 3.35+ (RETURNING). For asynchronous libSQL or Turso, use Store.sql.

Return type

type ReturnType = Store.AtomicStore
  • Provides get, put, delete, atomic update, and replay claims; see the AtomicStore contract.
  • Keep update callbacks synchronous and side-effect-free: conflicts rerun them.

Parameters

database

  • Type: Store.sqlite.Database

Database exposing prepare(sql).all(...params). Statements may expose reader and run(...params); the adapter calls run when reader === false, as better-sqlite3 requires.

options (optional)

  • Type: Store.sql.Options
PropertyTypeDefaultDescription
createTable (optional)booleantrueCreates the table on first use; set false for a migration-managed table.
keyPrefix (optional)stringNonePrefix for every backing key.
maxAttempts (optional)number32Maximum compare-and-swap attempts per update.
table (optional)string'mppx_store'Valid name or schema.name identifier.

See Store.sql for schema, migrations, serialization, and conflict errors.