kodkodkodkod

ORMs

Learn about Prisma, Drizzle, and Mongoose support in kodkod.

ORMs

kodkod supports three modern ORMs: Prisma, Drizzle, and Mongoose. The available options depend on your database choice:

  • PostgreSQL/MySQL: Prisma or Drizzle
  • MongoDB: Mongoose or Prisma

Prisma

Prisma is a next-generation ORM with auto-generated types, a visual database browser, and an intuitive schema language.

Best for:

  • Rapid development with auto-generated types
  • Teams who prefer declarative schema definitions
  • Projects needing Prisma Studio for database visualization
npx kodkod-stack@latest my-app --orm prisma

Schema Example

// prisma/schema.prisma
model User {
  id        String   @id @default(cuid())
  email     String   @unique
  name      String?
  createdAt DateTime @default(now())
}

Usage

import { db } from '../db';

// Create a user
const user = await db.user.create({
  data: { email: 'hello@example.com', name: 'Alice' }
});

// Find a user
const found = await db.user.findUnique({ where: { id: user.id } });

Commands

CommandDescription
npx prisma migrate devRun migrations in development
npx prisma generateGenerate Prisma client
npx prisma studioOpen visual database browser

Drizzle

Drizzle is a lightweight, SQL-like ORM that gives you full control over your queries while maintaining type safety.

Best for:

  • Developers who prefer writing SQL-like syntax
  • Projects requiring fine-grained query control
  • Lightweight deployments
npx kodkod-stack@latest my-app --orm drizzle

Schema Example

// src/db/schema.ts
import { pgTable, text, timestamp } from 'drizzle-orm/pg-core';

export const users = pgTable('users', {
  id: text('id').primaryKey(),
  email: text('email').notNull().unique(),
  name: text('name'),
  createdAt: timestamp('created_at').defaultNow(),
});

Usage

import { db } from '../db';
import { users } from '../db/schema';
import { eq } from 'drizzle-orm';

// Create a user
await db.insert(users).values({ id: '1', email: 'hello@example.com' });

// Find a user
const user = await db.select().from(users).where(eq(users.id, '1'));

Commands

CommandDescription
npx drizzle-kit pushPush schema changes to database
npx drizzle-kit generateGenerate migration files
npx drizzle-kit studioOpen visual database browser

Mongoose

Mongoose is the most popular MongoDB ODM for Node.js, providing schema validation and a rich query API.

Best for:

  • MongoDB-native development
  • Teams familiar with the MongoDB ecosystem
  • Projects needing schema validation and middleware
npx kodkod-stack@latest my-app --database mongodb --orm mongoose

Schema Example

// src/models/user.model.ts
import mongoose, { Schema, Document } from 'mongoose';

export interface IUser extends Document {
  email: string;
  name?: string;
}

const UserSchema = new Schema<IUser>({
  email: { type: String, required: true, unique: true },
  name: { type: String },
}, { timestamps: true });

export const User = mongoose.model<IUser>('User', UserSchema);

Usage

import { User } from '../models/user.model';

// Create a user
const user = await User.create({ email: 'hello@example.com', name: 'Alice' });

// Find a user
const found = await User.findById(userId);

// Update a user
await User.findByIdAndUpdate(userId, { name: 'Bob' });

Comparison

FeaturePrismaDrizzleMongoose
Query StyleMethod chainingSQL-likeDocument-based
Database SupportSQL + MongoDBSQL onlyMongoDB only
Bundle SizeLargerSmallerMedium
Type SafetyExcellentExcellentGood
Learning CurveEasierModerateEasier

On this page