drizzle-cuid2
Version:
A utility package for generating CUID2 columns in Drizzle ORM
49 lines (47 loc) • 1.23 kB
JavaScript
// src/sqlite-core/builder.ts
import { createId } from "@paralleldrive/cuid2";
import {
entityKind
} from "drizzle-orm";
import {
SQLiteColumn,
SQLiteColumnBuilder
} from "drizzle-orm/sqlite-core";
var SQLiteCuid2Builder = class extends SQLiteColumnBuilder {
static [entityKind] = "SQLiteCuid2Builder";
constructor(name) {
super(name, "string", "SQLiteCuid2");
}
build(table) {
return new SQLiteCuid2(
table,
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
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 SQLiteCuid2 = class extends SQLiteColumn {
static [entityKind] = "SQLiteCuid2";
getSQLType() {
return `text(24)`;
}
};
// src/sqlite-core/index.ts
function cuid2(name) {
return new SQLiteCuid2Builder(name ?? "");
}
export {
SQLiteCuid2Builder,
SQLiteCuid2,
cuid2
};
//# sourceMappingURL=chunk-KA3ZH5A5.mjs.map