Saas.js logo
Drizzle CRUD

Overview

A powerful TypeScript package that automatically generates CRUD operations for your Drizzle ORM schemas with built-in validation, filtering, pagination, soft deletes, and access control.

Drizzle CRUD

A powerful TypeScript package that automatically generates CRUD operations for your Drizzle ORM schemas with built-in validation, filtering, pagination, soft deletes, and access control.

This is an early preview version while we are working out details. We love to hear what you think @ https://x.com/saas_js or open a Discussion

Features

  • 🚀 Auto-generated CRUD operations from Drizzle schemas
  • 🔍 Advanced filtering with multiple operators (eq, ne, gt, lt, like, in, etc.)
  • 📄 Built-in pagination with configurable limits
  • 🔎 Full-text search across specified fields
  • 🗑️ Soft delete support with restore functionality
  • 🔐 Access control with actor-based permissions and scope filters
  • Standard schema validation with customizable schemas
  • 🪝 Lifecycle hooks for custom business logic
  • 📊 Bulk operations for efficient data manipulation
  • 🎯 Type-safe with full TypeScript support

Integrations (TBD)

  • tRPC generate crud procedures
  • Hono RPC generate hono RPC procedures
  • oRPC generate oRPC procedures
  • Tanstack Table Integrate pagination and filtering

Roadmap

  • Support all Drizzle dialects (currently only PG)
  • Expose utilities for filters and pagination
  • Define custom operations
  • Automatic re-ordering on insert or update (fractional/shift sorting)
  • Standard schema support

Quick Start

import { drizzleCrud } from 'drizzle-crud'
import { zod } from 'drizzle-crud/zod'
import { boolean, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core'
import { drizzle } from 'drizzle-orm/postgres-js'

// Define your schema
const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull(),
  isActive: boolean('is_active').default(true),
  deletedAt: timestamp('deleted_at'),
  createdAt: timestamp('created_at').defaultNow(),
})

// Initialize database and CRUD factory
const db = drizzle(/* your database connection */)
const createCrud = drizzleCrud(db, {
  validation: zod(),
})

// Create CRUD operations for each table
const userCrud = createCrud(users, {
  searchFields: ['name', 'email'],
  allowedFilters: ['isActive'],
  softDelete: { field: 'deletedAt' },
})

// Use the generated CRUD operations
const newUser = await userCrud.create({
  name: 'John Doe',
  email: 'john@example.com',
})

const usersList = await userCrud.list({
  search: 'john',
  filters: { isActive: true },
  page: 1,
  limit: 10,
})

Requirements

  • Node.js 16+
  • TypeScript 4.7+
  • Drizzle ORM
  • Zod v4

Next Steps