UNPKG

drizzle-cuid2

Version:

A utility package for generating CUID2 columns in Drizzle ORM

72 lines (69 loc) 2.34 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/pg-core/index.ts var pg_core_exports = {}; __export(pg_core_exports, { PgCuid2: () => PgCuid2, PgCuid2Builder: () => PgCuid2Builder, cuid2: () => cuid2 }); module.exports = __toCommonJS(pg_core_exports); // src/pg-core/builder.ts var import_cuid2 = require("@paralleldrive/cuid2"); var import_drizzle_orm = require("drizzle-orm"); var import_pg_core = require("drizzle-orm/pg-core"); var PgCuid2Builder = class extends import_pg_core.PgColumnBuilder { static [import_drizzle_orm.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 = () => (0, import_cuid2.createId)(); this.config.hasDefault = true; return this; } }; var PgCuid2 = class extends import_pg_core.PgColumn { static [import_drizzle_orm.entityKind] = "PgCuid2"; getSQLType() { return `varchar(24)`; } }; // src/pg-core/index.ts function cuid2(name) { return new PgCuid2Builder(name ?? ""); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { PgCuid2, PgCuid2Builder, cuid2 }); //# sourceMappingURL=index.js.map