Skip to content
VibORM
Esc
navigateopen⌘Jpreview
On this page

Bun SQLite

SQLite driver using Bun's built-in SQLite

Requirements

  • Bun runtime

Configuration

import { createClient } from "viborm/bun-sqlite";

const client = createClient({
  dataDir: "./database.sqlite",
  schema,
});

Options

Option Type Description
client Database Existing Bun SQLite database
dataDir string Path to SQLite file (:memory: for in-memory)
options object SQLite options

Options Object

Option Type Description
readonly boolean Open in read-only mode
create boolean Create file if it doesn’t exist
readwrite boolean Open with read-write access
strict boolean Enable strict mode

In-Memory Database

import { createClient } from "viborm/bun-sqlite";

// Default is in-memory
const client = createClient({
  schema,
});

Read-Only Mode

import { createClient } from "viborm/bun-sqlite";

const client = createClient({
  dataDir: "./database.sqlite",
  options: { readonly: true },
  schema,
});

Large integers

SQLite’s INTEGER is 64-bit, so a value past 2^53 cannot survive as a JS number. Typed reads opt the statement into Bun’s safeIntegers mode, so a s.bigInt() field round-trips exactly — the same guarantee sqlite3 and libsql give:

await client.measurement.create({
  data: { id: "m-1", views: 9_007_199_254_740_993n },
});

const row = await client.measurement.findUnique({ where: { id: "m-1" } });
row?.views; // 9007199254740993n — exact

$queryRawUnsafe bypasses the result parser and stays driver-native, so INTEGER columns come back as plain (possibly rounded) numbers there. Read large integers through a typed query, or through the tagged $queryRaw`...`.

Bun 1.1.14 or newer is required: on older builds the statement has no safeIntegers, and viborm refuses the read with a FeatureNotSupportedError rather than hand back a rounded value.

Transactions

Bun SQLite supports full transactions with savepoints for nested transactions — see Transactions.

Limitations

  • Only available in Bun runtime
  • JSON columns are parsed automatically
  • Boolean values stored as integers (0/1)
  • Synchronous API internally (async wrapper)

Was this page helpful?