UNPKG

drizzle-cuid2

Version:

A utility package for generating CUID2 columns in Drizzle ORM

48 lines (44 loc) 1.98 kB
import { ColumnBuilderBaseConfig, entityKind, MakeColumnConfig, HasDefault, ColumnBaseConfig, ColumnBuilderRuntimeConfig } from 'drizzle-orm'; import { SQLiteColumnBuilder, AnySQLiteTable, SQLiteColumn } from 'drizzle-orm/sqlite-core'; type SQLiteCuid2Config = { length: number; }; type SQLiteCuid2BuilderInitial<TName extends string> = Omit<SQLiteCuid2Builder<{ name: TName; dataType: 'string'; columnType: 'SQLiteCuid2'; data: string; driverParam: string; enumValues: undefined; }>, 'default' | '$default' | '$defaultFn'>; declare class SQLiteCuid2Builder<T extends ColumnBuilderBaseConfig<'string', 'SQLiteCuid2'>> extends SQLiteColumnBuilder<T> { static readonly [entityKind]: string; private length; constructor(name: string); build<TTableName extends string>(table: AnySQLiteTable<{ name: TTableName; }>): SQLiteCuid2<MakeColumnConfig<T, TTableName>>; /*** * 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(): HasDefault<this>; /*** * Sets the length of the CUID2 value. * @param length The length of the CUID2 value (default: 24) */ setLength(length: number): this; } declare class SQLiteCuid2<T extends ColumnBaseConfig<'string', 'SQLiteCuid2'>> extends SQLiteColumn<T> { static readonly [entityKind]: string; private length; constructor(table: AnySQLiteTable<{ name: string; }>, config: ColumnBuilderRuntimeConfig<T extends { $type: infer U; } ? U : T['data'], SQLiteCuid2Config>, length: number); getSQLType(): string; } declare function cuid2(): SQLiteCuid2BuilderInitial<''>; declare function cuid2<TName extends string>(name: TName): SQLiteCuid2BuilderInitial<TName>; export { SQLiteCuid2, SQLiteCuid2Builder, type SQLiteCuid2BuilderInitial, type SQLiteCuid2Config, cuid2 };