UNPKG

drizzle-cuid2

Version:

A utility package for generating CUID2 columns in Drizzle ORM

49 lines (47 loc) 1.22 kB
// src/mysql-core/builder.ts import { createId } from "@paralleldrive/cuid2"; import { entityKind } from "drizzle-orm"; import { MySqlColumn, MySqlColumnBuilder } from "drizzle-orm/mysql-core"; var MySqlCuid2Builder = class extends MySqlColumnBuilder { static [entityKind] = "MySqlCuid2Builder"; constructor(name) { super(name, "string", "MySqlCuid2"); } build(table) { return new MySqlCuid2( 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 MySqlCuid2 = class extends MySqlColumn { static [entityKind] = "MySqlCuid2"; getSQLType() { return `varchar(24)`; } }; // src/mysql-core/index.ts function cuid2(name) { return new MySqlCuid2Builder(name ?? ""); } export { MySqlCuid2Builder, MySqlCuid2, cuid2 }; //# sourceMappingURL=chunk-RIZ7MF4S.mjs.map