VibORM

better-sqlite3

SQLite driver using better-sqlite3

Installation

pnpm add better-sqlite3

Configuration

import { createClient } from "viborm/drivers/sqlite3";

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

Options

OptionTypeDescription
clientDatabaseExisting better-sqlite3 database
dataDirstringPath to SQLite file (:memory: for in-memory)
optionsobjectDatabase options

Options Object

OptionTypeDescription
readonlybooleanOpen in read-only mode
fileMustExistbooleanThrow if file doesn't exist
timeoutnumberBusy timeout in milliseconds
verbosefunctionLogging function

In-Memory Database

import { createClient } from "viborm/drivers/sqlite3";

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

Using Existing Database

import Database from "better-sqlite3";
import { createClient } from "viborm/drivers/sqlite3";

const db = new Database("./database.sqlite");

const client = createClient({
  client: db,
  schema,
});

Transactions

better-sqlite3 supports full transactions with savepoints for nested transactions.

await client.$transaction(async (tx) => {
  await tx.user.create({ data: { name: "Alice" } });
  await tx.post.create({ data: { title: "Hello", authorId: "..." } });
});

Features

  • Synchronous API (fastest SQLite driver for Node.js)
  • Full transaction support with savepoints
  • RETURNING clause support (SQLite 3.35+)

Limitations

  • SQLite dialect - no LATERAL joins, limited FULL OUTER JOIN
  • JSON columns return as strings and are parsed automatically
  • Boolean values stored as integers (0/1)
  • Node.js only (native module)

On this page