A utility package for generating CUID2 columns in Drizzle ORM (version 2.2.0). It provides a drop-in replacement for auto-increment or UUID primary keys using the collision-resistant CUID2 format. The package supports PostgreSQL, MySQL, and SQLite, and allows customizing CUID2 length and prefix. Requires drizzle-orm >=0.28.3. Differentiators: simpler API than raw cuid2 integration, database-specific functions (cuid2 for each dialect) and generic aliases (pgCuid2, mysqlCuid2, sqliteCuid2) for consistency.
npm install drizzle-cuid2No compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Defines two PostgreSQL tables (users and posts) using CUID2 primary keys with default random generation and a foreign key reference.
Use either `import { cuid2 } from 'drizzle-cuid2/postgres'` or `import { pgCuid2 } from 'drizzle-cuid2'`.Always call `.defaultRandom()` on the returned column: `cuid2('id').defaultRandom()`.Add `.defaultRandom()` to enable automatic CUID2 generation.
Ensure your project has drizzle-orm version 0.28.3 or higher.
Use a subpath like 'drizzle-cuid2/postgres' or import a named alias like 'pgCuid2' from 'drizzle-cuid2'.
Correct usage: `cuid2('id').defaultRandom()` (note the parentheses after cuid2).Upgrade drizzle-orm to >=0.28.3.