Drizzle <> Bun SQL

This guide assumes familiarity with:

According to the official website, Bun is a fast all-in-one JavaScript runtime.

Drizzle ORM natively supports bun sql module and it’s crazy fast 🚀

WARNING

In version 1.2.0, Bun has issues with executing concurrent statements, which may lead to errors if you try to run several queries simultaneously. We’ve created a github issue that you can track. Once it’s fixed, you should no longer encounter any such errors on Bun’s SQL side

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 'dotenv/config';
import { drizzle } from 'drizzle-orm/bun-sql';

const db = drizzle(process.env.DATABASE_URL);

const result = await db.select().from(...);

If you need to provide your existing driver:

import 'dotenv/config';
import { drizzle } from 'drizzle-orm/bun-sql';
import { SQL } from 'bun';

const client = new SQL(process.env.DATABASE_URL!);
const db = drizzle({ client });

What’s next?