Drizzle <> Node SQLite
This guide assumes familiarity with:
- Database connection basics with Drizzle
- Node - website
- Node SQLite driver - docs
Drizzle ORM natively supports node:sqlite module
We embrace SQL dialects and dialect specific drivers and syntax and unlike any other ORM,
for synchronous drivers like node:sqlite we have both async and sync APIs and we mirror most popular
SQLite-like all, get, values and run query methods syntax.
Step 1 - Install packages
npm
yarn
pnpm
bun
npm i drizzle-orm
npm i -D drizzle-kit
Step 2 - Initialize the driver and make a query
import { drizzle } from 'drizzle-orm/node-sqlite';
const db = drizzle("sqlite.db");
const result = await db.select().from(...);If you need to provide your existing driver:
import { drizzle } from 'drizzle-orm/node-sqlite';
import { DatabaseSync } from 'node:sqlite';
const sqlite = new DatabaseSync('sqlite.db');
const db = drizzle({ client: sqlite });
const result = await db.select().from(...);If you want to use sync APIs:
import { drizzle } from 'drizzle-orm/node-sqlite';
import { DatabaseSync } from 'node:sqlite';
const sqlite = new Database('sqlite.db');
const db = drizzle({ client: sqlite });
const result = db.select().from(users).all();
const result = db.select().from(users).get();
const result = db.select().from(users).values();
const result = db.select().from(users).run();