Drizzle <> Bun SQLite
This guide assumes familiarity with:
- Database connection basics with Drizzle
- Bun - website
- Bun SQLite driver - docs
According to the official website, Bun is a fast all-in-one JavaScript runtime.
Drizzle ORM natively supports bun:sqlite
module and it’s crazy fast 🚀
We embraces SQL dialects and dialect specific drivers and syntax and unlike any other ORM, for synchronous drivers like bun: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/bun-sqlite'; const db = drizzle(); const result = await db.select().from(...);
If you need to provide your existing driver:
import { drizzle } from 'drizzle-orm/bun-sqlite'; import { Database } from 'bun:sqlite'; const sqlite = new Database('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/bun-sqlite'; import { Database } from 'bun: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();