CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-drizzle-orm

TypeScript ORM for SQL databases with type-safe queries, schema definitions, and support for PostgreSQL, MySQL, SQLite, and more.

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

Drizzle ORM

Lightweight, headless TypeScript ORM for SQL databases providing a thin typed layer on top of SQL. Supports PostgreSQL, MySQL, SQLite, SingleStore, and GEL with zero runtime dependencies.

Quick Start

import { drizzle } from 'drizzle-orm/node-postgres';
import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core';
import { eq } from 'drizzle-orm';
import { Pool } from 'pg';

// Define schema
const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: varchar('email', { length: 255 }).notNull().unique(),
});

// Initialize database
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
const db = drizzle(pool);

// Query data
const allUsers = await db.select().from(users);
const user = await db.select().from(users).where(eq(users.id, 1));

// Insert data
await db.insert(users).values({ name: 'John', email: 'john@example.com' });

// Update data
await db.update(users).set({ name: 'Jane' }).where(eq(users.id, 1));

// Delete data
await db.delete(users).where(eq(users.id, 1));

Core Concepts

  • Type-Safe Schema Definition: Declare tables, columns, and constraints in TypeScript
  • Query Builder: Composable, type-safe SQL query builders
  • Relational Queries: High-level API for loading related data
  • Zero Dependencies: Minimal bundle size (~7.4kb)
  • Multiple Databases: PostgreSQL, MySQL, SQLite, SingleStore, GEL
  • 20+ Drivers: Support for serverless, edge, and embedded databases

Installation

npm install drizzle-orm

For specific drivers:

npm install drizzle-orm pg              # PostgreSQL (node-postgres)
npm install drizzle-orm postgres       # PostgreSQL (postgres-js)
npm install drizzle-orm mysql2         # MySQL
npm install drizzle-orm better-sqlite3 # SQLite

Core Imports

import { drizzle } from 'drizzle-orm/[driver]';
import { pgTable, serial, text, varchar } from 'drizzle-orm/pg-core';
import { eq, and, or, sql } from 'drizzle-orm';

Replace [driver] with: node-postgres, postgres-js, mysql2, better-sqlite3, libsql, neon-serverless, etc.

Type Inference

type InferSelectModel<TTable> = // Infer SELECT result type
type InferInsertModel<TTable> = // Infer INSERT input type

// Also available as properties:
table.$inferSelect // Type of SELECT result
table.$inferInsert // Type of INSERT input

Configuration

interface DrizzleConfig<TSchema> {
  logger?: Logger | boolean;
  schema?: TSchema;
  casing?: 'snake_case' | 'camelCase';
  cache?: Cache;
}

Database Support Matrix

DatabaseDriversKey Features
PostgreSQLpg, postgres-js, Neon, Vercel, AWS RDS, PGlite, Xata, SupabaseJSONB, arrays, enums, PostGIS, pgvector, RLS, materialized views
MySQLmysql2, PlanetScale, TiDBJSON, full-text indexes, spatial indexes
SQLitebetter-sqlite3, Bun, libSQL/Turso, D1, Expo, OP SQLite, sql.jsJSON mode, RETURNING, embedded/serverless
SingleStorenative driverMySQL-compatible with optimizations
GELnative driverEdgeDB-like features

Documentation Structure

Guides

  • Quick Start Guide - Step-by-step setup and basic usage

Examples

Reference

Error Handling

class DrizzleError extends Error {}
class DrizzleQueryError extends DrizzleError {}
class TransactionRollbackError extends DrizzleError {}

Architecture

  • Type System: Full TypeScript integration with automatic inference
  • Schema Definition: Builder functions for tables, columns, constraints
  • Query Builder: Composable, type-safe SQL operations
  • Relational Queries: Optional high-level API with automatic joins
  • Database Drivers: 20+ adapters for various platforms
  • Serverless-First: Optimized for edge runtimes and serverless functions
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/drizzle-orm@0.45.x
Publish Source
CLI
Badge
tessl/npm-drizzle-orm badge