quiverdb
v0.13.8
Published
SQLite wrapper binding for Quiver via Bun FFI (`bun:ffi`).
Readme
quiverdb
SQLite wrapper binding for Quiver via Bun FFI (bun:ffi).
Requirements
- Bun >= 1.1
libquiver.dllandlibquiver_c.dll(or.so/.dylib) accessible (see Native Library Setup)
Installation
bun add quiverdbThe bundled native libraries ship inside the package, so no separate download step is required on supported platforms. To build the native libraries from source, see the Quiver project build instructions.
import { Database } from "quiverdb";Bun loads native code via FFI without any permission flags — unlike Deno, there
is no --allow-ffi/--allow-read/--allow-write to pass.
Native Library Setup
The loader searches for native libraries in three tiers:
- Bundled:
libs/{os}-{arch}/directory next to the binding source (shipped inside the published package). - Dev mode: Walks up directories looking for
build/bin/(auto-discovered during in-tree development against a local C++ build). - System PATH: Falls back to loading by library name.
Currently prebuilt binaries ship for linux-x86_64, macos-aarch64, and
windows-x86_64. On other platforms, build from source and point to build/bin/
via tier 2.
Quick Start
import { Database } from "quiverdb";
const db = Database.fromSchema("my.db", "schema.sql");
db.createElement("Items", { label: "Item 1", value: 42 });
const values = db.readScalarIntegers("Items", "value");
console.log(values); // [42]
db.close();Run with:
bun run example.tsAPI Methods
Lifecycle
Database.fromSchema(dbPath, schemaPath, options?)-- Create database from SQL schema fileDatabase.fromMigrations(dbPath, migrationsPath, options?)-- Create database from migrations directoryDatabase.open(dbPath, options?)-- Open an existing database file; the schema loads on first useDatabase.validateMigrations(migrationsPath)-- Validate a migrations directory (everyup.sql, then everydown.sql, ending with no table left behind) in-memory; throws on failureclose()-- Close the database connection
All opening methods accept logPath, for example
Database.open("study.db", { logPath: "logs/study.log" }). Relative paths use the database's
directory, or the current working directory for :memory:. A nonempty path enables file
logging for read-only and in-memory databases too. Parent directories are created, the file is
truncated on open, and an unusable explicit path throws QuiverError. Omitting logPath or
passing "" keeps the defaults: quiver_database.log beside a writable file database and
console-only logging for read-only/in-memory databases. consoleLevel filters only the console.
Create / Delete
createElement(collection, data)-- Create element, returns numeric IDupdateElement(collection, id, data)-- Update element by IDdeleteElement(collection, id)-- Delete element by IDupdateElementByLabel(collection, label, data)-- Update element by labeldeleteElementByLabel(collection, label)-- Delete element by labelupdateRelation(collectionFrom, collectionTo, relationType, id, targetLabel)-- Point a scalar relation at the element labelledtargetLabel(nullclears it)updateRelationByLabel(collectionFrom, collectionTo, relationType, label, targetLabel)-- Same, addressing the element by labelupdateVectorGroup(collection, group, id, data)-- Replace an element's rows in one named vector group ({}clears it)updateVectorGroupByLabel(collection, group, label, data)-- Same, addressing the element by labelupdateSetGroup(collection, group, id, data)-- Replace an element's rows in one named set group ({}clears it)updateSetGroupByLabel(collection, group, label, data)-- Same, addressing the element by label
Read (bulk)
readScalarIntegers(collection, attribute)-- Read all integer scalarsreadScalarBooleans(collection, attribute)-- Read INTEGER-backed boolean scalarsreadScalarFloats(collection, attribute)-- Read all float scalarsreadScalarStrings(collection, attribute)-- Read all string scalarsreadVectorIntegers(collection, attribute)-- Read all integer vectorsreadVectorBooleans(collection, attribute)-- Read INTEGER-backed boolean vectorsreadVectorFloats(collection, attribute)-- Read all float vectorsreadVectorStrings(collection, attribute)-- Read all string vectorsreadSetIntegers(collection, attribute)-- Read all integer setsreadSetBooleans(collection, attribute)-- Read INTEGER-backed boolean setsreadSetFloats(collection, attribute)-- Read all float setsreadSetStrings(collection, attribute)-- Read all string sets
Read (by ID)
readScalarIntegerById(collection, attribute, id)-- Read integer or nullreadScalarBooleanById(collection, attribute, id)-- Read INTEGER-backed boolean or nullreadScalarFloatById(collection, attribute, id)-- Read float or nullreadScalarStringById(collection, attribute, id)-- Read string or nullreadVectorIntegersById(collection, attribute, id)-- Read integer vectorreadVectorBooleansById(collection, attribute, id)-- Read INTEGER-backed boolean vectorreadVectorFloatsById(collection, attribute, id)-- Read float vectorreadVectorStringsById(collection, attribute, id)-- Read string vectorreadSetIntegersById(collection, attribute, id)-- Read integer setreadSetBooleansById(collection, attribute, id)-- Read INTEGER-backed boolean setreadSetFloatsById(collection, attribute, id)-- Read float setreadSetStringsById(collection, attribute, id)-- Read string setreadVectorGroupById(collection, group, id)-- Read a whole vector group as rows (nullfor a SQL NULL cell)readSetGroupById(collection, group, id)-- Read a whole set group as rows (nullfor a SQL NULL cell)
Read (IDs)
readElementIds(collection)-- Read all element IDs in a collectionnumberOfElements(collection)-- Current number of elements in a collection
Metadata
getScalarMetadata(collection, attribute)-- Get scalar attribute metadatagetVectorMetadata(collection, attribute)-- Get vector group metadatagetSetMetadata(collection, attribute)-- Get set group metadatagetTimeSeriesMetadata(collection, attribute)-- Get time series group metadatalistScalarAttributes(collection)-- List all scalar attributeslistVectorGroups(collection)-- List all vector groupslistSetGroups(collection)-- List all set groupslistTimeSeriesGroups(collection)-- List all time series groups
Time Series
readTimeSeriesGroup(collection, group, id)-- Read time series data for an elementupdateTimeSeriesGroup(collection, group, id, data)-- Write time series data for an element ({}clears it)updateTimeSeriesGroupByLabel(collection, group, label, data)-- Same, addressing the element by labelreadTimeSeriesRow(collection, group, attribute, dateTime)-- One value per element: the last non-null value at or beforedateTime, ornullif there is noneupsertTimeSeriesRow(collection, group, id, row)-- Insert or patch one row, keyed by its dimension valueupsertTimeSeriesRowByLabel(collection, group, label, row)-- Same, addressing the element by labelhasTimeSeriesFiles(collection)-- Check whether the collection has a time series files tablelistTimeSeriesFilesColumns(collection)-- List the time series files columnsreadTimeSeriesFiles(collection)-- Read the file paths (nullfor an unset column)updateTimeSeriesFiles(collection, data)-- Write the file paths
Query (read-only SQL)
queryString(sql, parameters?)-- Query returning string or nullqueryInteger(sql, parameters?)-- Query returning integer or nullqueryBoolean(sql, parameters?)-- Query returning an INTEGER-backed boolean or nullqueryFloat(sql, parameters?)-- Query returning float or null
Parameters are passed as an array of number | bigint | boolean | string | null (a bigint binds
as an exact INTEGER, a boolean as the INTEGER 1 or 0).
Transaction
beginTransaction()-- Begin explicit transactioncommit()-- Commit current transactionrollback()-- Rollback current transactioninTransaction()-- Check if transaction is activebeginDryRun()-- Begin a dry run: a transactionendDryRun()always rolls back. While it is active,beginTransaction/commit/rollbackare absorbed (no-ops)endDryRun()-- End the active dry run, rolling back everything it coveredinDryRun()-- Check if a dry run is active
CSV
exportCsv(collection, group, filePath, options?)-- Export collection group to CSV fileimportCsv(collection, group, filePath, options?)-- Import CSV file into collection group
Composites
readScalarsById(collection, id)-- Read all scalar attributes for an elementreadVectorsById(collection, id)-- Read all vector groups for an elementreadSetsById(collection, id)-- Read all set groups for an element
Introspection
The describe methods give agents the schema, attribute meanings and data coverage as text reports.
describe()-- Database/version header followed by complete reports for every collectiondescribeCollection(collection)-- One collection's structure, UI metadata (including tooltips), scalar null/value statistics and group coverage, returned as a string. Enum meanings appear once inenum {...}; value histograms contain numeric codes and counts.isHealthy()-- Check database healthpath()-- Get database file pathcurrentVersion()-- Get current schema version
Lua
Sandbox(db)-- Create Lua script runner with database accessrun(script, { timeoutMs? })-- Execute a Lua script; returns its return value as a JSON string, or""if it returned nothing.timeoutMs> 0 stops a script still running after that many milliseconds (default 0, no limit)close()-- Close the Sandbox
Lua print() writes and flushes an INFO entry through the database logger. An explicit logPath
selects the file even for read-only and in-memory databases. Without it, writable file databases
use quiver_database.log, while read-only and in-memory databases use console logging only.
LOG_LEVEL_OFF suppresses console output. Script return values remain separate JSON.
Types
Exported types available for TypeScript consumers:
ScalarValue--number | bigint | boolean | string | null(abooleanis stored as INTEGER 1/0)ArrayValue--number[] | bigint[] | boolean[] | string[]Value--ScalarValue | ArrayValueElementData--Record<string, Value | undefined>QueryParam--number | bigint | boolean | string | nullGroupColumns--Record<string, (number | bigint | string | boolean | null)[]>, the column-oriented payload ofupdateTimeSeriesGroup/updateVectorGroup/updateSetGroup(and theirByLabelforms)QuiverError-- Error class for all Quiver operationsScalarMetadata-- Scalar attribute metadataGroupMetadata-- Vector/set/time series group metadataTimeSeriesData-- Time series column dataCsvOptions-- CSV import/export optionsDatabaseOptions--{ readOnly?: boolean; consoleLevel?: number; logPath?: string }(consoleLevelis aLOG_LEVEL_*constant)LOG_LEVEL_DEBUG | INFO | WARN | ERROR | OFF,DATA_TYPE_INTEGER | FLOAT | STRING | DATE_TIME | NULL-- constants forDatabaseOptions.consoleLeveland metadatadataType
Development
bun install # Install dev dependencies (@types/bun, biome)
bun test test # Run all tests
bun run lint # Biome linting
bun run format # Biome formatting (auto-fix)Tests discover the native library from a local build/bin/ (tier 2). On Windows,
prepend build/bin to PATH first (the test/test.bat helper does this for you).
License
MIT
