Getting Started

db0 provides an easy way to connect and query sql database providers.

DB0 development is in the early stages. Follow up progress via GitHub issues.

DB0 is a lightweight SQL connector:

✅ Works with several SQL connectors.

✅ Can be integrated with ORMs and embedded into frameworks.

✅ Provides a simple but elegant query API out of the box.

Quick start

Install db0 npm package:

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

// Initiate database with SQLite connector
const db = createDatabase(sqlite({}));

// Create users table
await db.sql`CREATE TABLE IF NOT EXISTS users ("id" TEXT PRIMARY KEY, "firstName" TEXT, "lastName" TEXT, "email" TEXT)`;

// Add a new user
const userId = "1001";
await db.sql`INSERT INTO users VALUES (${userId}, 'John', 'Doe', '')`;

// Query for users
const { rows } = await db.sql`SELECT * FROM users WHERE id = ${userId}`;
console.log(rows);

// Using static parameters
const tableName = "users";
const { rows } =
  await db.sql`SELECT * FROM {${tableName}} WHERE id = ${userId}`;
console.log(rows);
> Static Parameters are a way to use string-literals other than places where prepared statements are supported, for eg. table name. DO NOT USE static parameters from untrusted source such as request body. STATIC PARAMETERS ARE NOT SANITIZED

Next steps

Read more in Connectors.
Read more in Integrations.