Skip to content

Getting Started

direct-sqlite is a high-performance, type-safe SQLite database binding layer optimized for modern JavaScript runtimes. It eliminates heavy intermediate ORM parsing layers to execute queries with near-zero runtime abstraction overhead.

Install the package alongside your preferred workspace database driver dependencies.

Terminal window
pnpm add direct-sqlite

Follow these steps to instantiate your database instance and run your first compile-time validated query.

  1. Define Your Schema Struct

    Create your tables using the structural column schema builders:

    src/db/schema.ts
    import { table, text, integer } from '@direct-sqlite/schema';
    export const users = table('users', {
    id: integer('id').primaryKey(),
    name: text('name').notNull(),
    email: text('email').unique(),
    })
  2. Initialize the Core Driver Interface

    Pass your native runtime SQLite database handle directly into the core wrapper instance:

    src/db/index.ts
    import { Database } from '@direct-sqlite/core';
    import SQLite from 'better-sqlite3';
    import * as schema from './schema';
    const nativeDb = new SQLite('local.db');
    // Instantiate the core direct binding agent
    export const db = new Database(nativeDb, { schema });
  3. Execute Type-Safe Queries

    Import your database instance context layer directly to leverage auto-complete and full mutation pipelines:

    import { db } from './db';
    import { users } from './db/schema';
    // Fully type-safe result dataset arrays matching your table schema
    const activeUsers = await db.select().from(users).execute();
    console.log(activeUsers);