quiverdb
v0.9.5
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)-- Create database from SQL schema fileDatabase.fromMigrations(dbPath, migrationsPath)-- Create database from migrations directoryclose()-- Close the database connection
Create / Delete
createElement(collection, data)-- Create element, returns numeric IDupdateElement(collection, id, data)-- Update element by IDdeleteElement(collection, id)-- Delete element by ID
Read (bulk)
readScalarIntegers(collection, attribute)-- Read all integer scalarsreadScalarFloats(collection, attribute)-- Read all float scalarsreadScalarStrings(collection, attribute)-- Read all string scalarsreadVectorIntegers(collection, attribute)-- Read all integer vectorsreadVectorFloats(collection, attribute)-- Read all float vectorsreadVectorStrings(collection, attribute)-- Read all string vectorsreadSetIntegers(collection, attribute)-- Read all integer setsreadSetFloats(collection, attribute)-- Read all float setsreadSetStrings(collection, attribute)-- Read all string sets
Read (by ID)
readScalarIntegerById(collection, attribute, id)-- Read integer or nullreadScalarFloatById(collection, attribute, id)-- Read float or nullreadScalarStringById(collection, attribute, id)-- Read string or nullreadVectorIntegersById(collection, attribute, id)-- Read integer vectorreadVectorFloatsById(collection, attribute, id)-- Read float vectorreadVectorStringsById(collection, attribute, id)-- Read string vectorreadSetIntegersById(collection, attribute, id)-- Read integer setreadSetFloatsById(collection, attribute, id)-- Read float setreadSetStringsById(collection, attribute, id)-- Read string set
Read (IDs)
readElementIds(collection)-- Read all element IDs 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
Query
queryString(sql, parameters?)-- Query returning string or nullqueryInteger(sql, parameters?)-- Query returning integer or nullqueryFloat(sql, parameters?)-- Query returning float or null
Parameters are passed as an array of number | string | null.
Transaction
beginTransaction()-- Begin explicit transactioncommit()-- Commit current transactionrollback()-- Rollback current transactioninTransaction()-- Check if transaction 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
describe()-- Print schema info to stdoutisHealthy()-- Check database healthpath()-- Get database file pathcurrentVersion()-- Get current schema version
Lua
LuaRunner(db)-- Create Lua script runner with database accessrun(script)-- Execute a Lua scriptclose()-- Close the Lua runner
Types
Exported types available for TypeScript consumers:
ScalarValue--number | bigint | string | nullArrayValue--number[] | bigint[] | string[]Value--ScalarValue | ArrayValueElementData--Record<string, Value | undefined>QueryParam--number | string | nullQuiverError-- Error class for all Quiver operationsScalarMetadata-- Scalar attribute metadataGroupMetadata-- Vector/set/time series group metadataTimeSeriesData-- Time series column dataCsvOptions-- CSV import/export options
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
