@itboom/drizzle-utils is a utility library for working with Drizzle ORM in a
type-safe and ergonomic way.
It includes createPgEnum() — a simple helper to safely generate PostgreSQL
enums from string enums or string arrays.
⚠️ Does not support numeric enums for safety reasons.
- ✅ Safe string-only enum extraction
- 🧠 Clear runtime validation of enum values
- 📦 Tiny footprint with zero dependencies
- ⚡ Compatible with any
pgTable()column definition
bun add @itboom/drizzle-utilsnpm install @itboom/drizzle-utilsimport{createPgEnum}from"@itboom/drizzle-utils/pg";enumUserRole{ADMIN="admin",MODERATOR="moderator",USER="user",}constuserRole=createPgEnum("user_role",UserRole);pgTable("user",{role: userRole().default(UserRole.USER).notNull(),});import{createPgEnum}from"@itboom/drizzle-utils/pg";conststatus=createPgEnum("listing_status",["DRAFT","ACTIVE","ARCHIVED"]);pgTable("listing",{status: status().notNull(),});import{boolean,integer,pgTable,timestamp,uuid,varchar,}from"drizzle-orm/pg-core";import{createPgEnum}from"@itboom/drizzle-utils/pg";enumUserRole{ADMIN="admin",MODERATOR="moderator",USER="user",}constuserRole=createPgEnum("user_role",UserRole);exportconstuser=pgTable("user",{id: uuid().defaultRandom().primaryKey(),role: userRole().default(UserRole.USER).notNull(),email: varchar({length: 255}).notNull().unique(),name: varchar({length: 255}),createdAt: timestamp({mode: "date"}).defaultNow(),});Creates a reusable PostgreSQL enum column for Drizzle.
name— the enum name in the databasevalues— either a string enum or an array of string values
Returns a column factory function usable in pgTable().
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome!
Please open an issue or submit a PR to extend features or improve typing.
Created by Bohdan Kulinchenko
Founder of itboom.dev
GitHub: @ITBoomDev
Happy typing with @itboom/drizzle-utils! ✨