UNPKG

drizzle-cuid2

Version:

A utility package for generating CUID2 columns in Drizzle ORM

49 lines (47 loc) 1.17 kB
// src/pg-core/builder.ts import { createId } from "@paralleldrive/cuid2"; import { entityKind } from "drizzle-orm"; import { PgColumn, PgColumnBuilder } from "drizzle-orm/pg-core"; var PgCuid2Builder = class extends PgColumnBuilder { static [entityKind] = "PgCuid2Builder"; constructor(name) { super(name, "string", "PgCuid2"); } build(table) { return new PgCuid2( table, // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument this.config ); } /*** * Creates a random `cuid2` value as the default value for the column. * The function will be called when the row is inserted, and the returned value will be used as the column value. */ defaultRandom() { this.config.defaultFn = () => createId(); this.config.hasDefault = true; return this; } }; var PgCuid2 = class extends PgColumn { static [entityKind] = "PgCuid2"; getSQLType() { return `varchar(24)`; } }; // src/pg-core/index.ts function cuid2(name) { return new PgCuid2Builder(name ?? ""); } export { PgCuid2Builder, PgCuid2, cuid2 }; //# sourceMappingURL=chunk-L7V57AGM.mjs.map