ormDB

ormDB + Drizzle

Language: typescriptPackage: @ormdb/drizzle-adapterStatus: beta

What This Adapter Does

ormDB is a relational database engine written in Rust that replaces PostgreSQL, MySQL, and SQLite as the actual database underneath your application. The @ormdb/drizzle-adapter package connects Drizzle ORM to ormDB, letting you keep your existing Drizzle schema definitions and type-safe queries while the database itself resolves object graphs natively.

Drizzle already offers a relational query API with its with clause. When you query users with their posts and comments using Drizzle’s relational API, traditional databases still decompose that into multiple SQL queries, causing N+1 problems. ormDB receives the graph-fetch intent directly and resolves the entire relation tree in one round-trip.

Quick Setup

Install the adapter:

npm install @ormdb/drizzle-adapter

Configure the ormDB connection:

import { drizzle } from '@ormdb/drizzle-adapter'
import * as schema from './schema'

const db = drizzle(process.env.ORMDB_URL, { schema })

// Relational queries resolve in a single round-trip
const users = await db.query.users.findMany({
  with: {
    posts: {
      with: {
        comments: true,
        tags: true,
      },
    },
  },
})

Your existing Drizzle schema definitions require no changes:

import { entity, text, relation } from '@ormdb/drizzle-adapter/schema'

export const users = entity('users', {
  id: text('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull(),
})

export const posts = entity('posts', {
  id: text('id').primaryKey(),
  title: text('title').notNull(),
  authorId: text('author_id').references(() => users.id),
})

What Changes, What Stays the Same

Stays the same: Your Drizzle schema files, relational query API (db.query), CRUD operations (select, insert, update, delete), type inference, and relation declarations.

Changes: The database engine. Nested with clauses become single-round-trip graph fetches. Migrations gain A-D safety grading. Vector search, geo search, full-text search, and change streams are available natively without extensions. Drizzle with ormDB is ideal for TypeScript projects.

Removed: Raw SQL via the sql template literal tag and any direct SQL string execution. All queries must go through Drizzle’s type-safe API. See how ormDB compares to the databases Drizzle typically connects to: PostgreSQL and SQLite.

Frequently Asked Questions

Do Drizzle's relational queries work with ormDB?

Yes. Drizzle's relational query API maps directly to ormDB's graph-fetch protocol. The with clause in Drizzle relational queries becomes a native graph fetch in ormDB, resolving all nested relations in a single round-trip.

Does Drizzle's SQL-like query builder still work?

Drizzle's select/insert/update/delete query builder is supported. The adapter translates these into ormDB's native operations. Raw SQL via sql`` template literals is not supported because ormDB does not use SQL.

Can I use Drizzle Kit migrations with ormDB?

The adapter integrates with Drizzle Kit's migration workflow. Migrations are routed through ormDB's engine, which grades each change from A (safe) to D (destructive) before applying it.

What about Drizzle's performance benefits like prepared statements?

ormDB's zero-copy wire protocol (rkyv) eliminates serialization overhead entirely, providing performance advantages that go beyond what prepared statements offer in traditional SQL databases.

Is this adapter production-ready?

The adapter is in beta. ormDB itself is in Alpha v0.1.0. It is suitable for development and testing workloads today.

Related Content

Try ormDB today

Open source, MIT licensed. Install and start building.