Connectors

SQLite

Connect DB0 to local SQLite database with Node.js

You have two options for using SQLite with Node.js: better-sqlite3 and sqlite3.

Unless needed for compatibility reasons, better-sqlite3 is recommended.

better-sqlite3

Read more in better-sqlite3.

For this connector, you need to install better-sqlite3 dependency:

npm i better-sqlite3

Use better-sqlite3 connector:

import { createDatabase } from "db0";
import sqlite from "db0/connectors/better-sqlite3";

const db = createDatabase(
  sqlite({
    name: ":memory:",
  }),
);

Options

cwd

Working directory to create database. Default is current working directory of project. (It will be ignored if path is provided an absolute path.)

name

Database (file) name. Default is db.

You can use :memory: as name for in-memory storage.

path

Related (to cwd) or absolute path to the sql file. By default it is stored in {cwd}/.data/{name}.sqlite3 / .data/db.sqlite3

node-sqlite3

Read more in node-sqlite3.

For this connector, you need to install sqlite3 dependency:

npm i sqlite3

Use node-sqlite3 connector:

import { createDatabase } from "db0";
import sqlite from "db0/connectors/node-sqlite3";

const db = createDatabase(
  sqlite({
    name: ":memory:",
  }),
);

Options

(same as better-sqlite3)