Open-source package
drizzle-cuid2
Typed CUID2 column builders for Drizzle ORM across PostgreSQL, MySQL and SQLite, used thousands of times each week.
- Reach
- 2k+ weekly npm downloads
- Databases
- PostgreSQL · MySQL · SQLite
- License
- MIT
The problem
CUID2 works well as an application-generated identifier, but using it as a first-class Drizzle column meant repeating the same setup and giving up the fluent, database-aware column API.
The small solution
The package exposes native-looking column builders for each supported Drizzle dialect. They retain methods such as primaryKey, notNull and references, then add defaultRandom, setLength and setPrefix for CUID2-specific behaviour.
Actual usage
A PostgreSQL primary key keeps Drizzle's fluent column API while generating the identifier in the application:
import { pgTable } from "drizzle-orm/pg-core"
import { cuid2 } from "drizzle-cuid2/postgres"
export const users = pgTable("users", {
id: cuid2("id").defaultRandom().primaryKey(),
})Why three implementations
PostgreSQL, MySQL and SQLite have different column base classes and SQL types. Keeping a thin builder for each dialect preserves Drizzle's type inference and emits the appropriate varchar or text definition without asking users to maintain that code themselves.