Registry / database / drizzle-orm

drizzle-orm

JSON →
library0.45.2jsnpmunverified

Drizzle ORM is a lightweight, TypeScript-first ORM for SQL databases, offering a flexible API for database interactions, schema definition, and migrations. The current stable version is `0.45.2`, with active development ongoing on the `1.0.0-beta` branch, seeing frequent new features and fixes. Stable releases are less frequent, focusing on critical bug fixes.

npm install drizzle-orm
INSTALL
IMPORT
SIG · DRIZZLE-ORM
D
drizzle-orm
databasejavascriptv0.45.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

drizzle
import { drizzle } from 'drizzle-orm/postgres-js';
const drizzle = require('drizzle-orm/postgres-js');
The main `drizzle` function is imported from a specific driver package (e.g., `drizzle-orm/postgres-js`, `drizzle-orm/better-sqlite3`).

Connects to an in-memory SQLite database using `better-sqlite3`, defines a simple schema, inserts data, and queries it, demonstrating basic Drizzle ORM usage.

import { drizzle } from 'drizzle-orm/better-sqlite3'; import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'; import Database from 'better-sqlite3'; // Initialize an in-memory SQLite database const sqlite = new Database(':memory:'); const db = drizzle(sqlite); // Define a simple schema for users export const users = sqliteTable('users', { id: integer('id').primaryKey(), name: text('name').notNull(), }); async function main() { // For quickstart, manually create the table. In production, use Drizzle Kit for migrations. sqlite.exec(` CREATE TABLE IF NOT EXISTS users ( id INTEGER PRIMARY KEY, name TEXT NOT NULL ); `); // Insert data await db.insert(users).values({ id: 1, name: 'Alice' }).execute(); await db.insert(users).values({ id: 2, name: 'Bob' }).execute(); // Query data const allUsers = db.select().from(users).all(); console.log('Users:', allUsers); // Expected output: Users: [{ id: 1, name: 'Alice' }, { id: 2, name: 'Bob' }] sqlite.close(); } main();
drizzle-kit --version
Debug
Known issues
breakingPreviously, `sql.identifier()` and `sql.as()` functions were not properly escaping values, leading to a potential SQL Injection vulnerability (CWE-89).
fix
Upgrade to `drizzle-orm@0.45.2` or `v1.0.0-beta.20` and later to ensure automatic escaping. Always validate or sanitize user-provided identifiers if they are directly used in these functions.
affects: <=0.45.1, <1.0.0-beta.20
breakingA significant regression in the migration infrastructure was present, potentially causing issues with migration tracking, validation, and application.
fix
Upgrade to `1.0.0-beta.16` or later to resolve these migration issues, which included a redesign of the underlying migration architecture.
affects: >=1.0.0-beta.13 <1.0.0-beta.16
gotchaAdding a new value to a PostgreSQL enum will no longer be automatically treated as a commutative (non-breaking) change in migration generation by `drizzle-kit`.
fix
Review and manually adjust migration files if adding enum values, especially when merging branches that add different enum values, as they will now be properly merged instead of being treated as commutative.
affects: >=1.0.0-beta.21
gotchaMSSQL `real()` column types might return imprecise `float64` values due to a missing `mapFromDriverValue` implementation.
fix
Upgrade to `1.0.0-beta.22` or later for correct `real()` column value mapping and precision in MSSQL.
affects: <=1.0.0-beta.21
Errors
Common errors & fixes
ER_PARSE_ERROR: You have an error in your SQL syntax
Untrusted input was passed to `sql.identifier()` or `sql.as()` without proper escaping in Drizzle ORM versions prior to 0.45.2 or 1.0.0-beta.20, leading to malformed SQL queries.
fix
Upgrade Drizzle ORM to at least `0.45.2` (or `1.0.0-beta.20`) to ensure automatic escaping. Always validate or sanitize user-provided identifiers if they are directly used in `sql.identifier()`.
Error: DrizzleError: Object key collision detected. Make sure your schema definitions are unique.
Multiple schema definitions (e.g., tables, columns, relations) with the same key were found within your Drizzle ORM schema, leading to a conflict during processing.
fix
Review your Drizzle ORM schema files and ensure that all table, column, and relation definitions have unique names to prevent key collisions.
Error: D1_ERROR: ... syntax error near '...'
Migration script generated by `drizzle-kit` contained incompatible SQL syntax or commands for Cloudflare D1, or there were environment setup issues specific to D1.
fix
Upgrade `drizzle-kit` to the latest version (>=0.31.10) as a fix for D1 migration failures was released. Also, ensure your D1 environment is correctly configured and consult Drizzle ORM's official documentation for D1-specific migration guidelines.
Upgrade
Version history
0.45.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
drizzle-orm — npm install drizzle-orm · libregistry