UNPKG

drizzle-cuid2

Version:

A utility package for generating CUID2 columns in Drizzle ORM

48 lines (44 loc) 1.89 kB
import { ColumnBuilderBaseConfig, entityKind, MakeColumnConfig, HasDefault, ColumnBaseConfig, ColumnBuilderRuntimeConfig } from 'drizzle-orm'; import { PgColumnBuilder, AnyPgTable, PgColumn } from 'drizzle-orm/pg-core'; type PgCuid2Config = { length: number; }; type PgCuid2BuilderInitial<TName extends string> = Omit<PgCuid2Builder<{ name: TName; dataType: 'string'; columnType: 'PgCuid2'; data: string; driverParam: string; enumValues: undefined; }>, 'default' | '$default' | '$defaultFn'>; declare class PgCuid2Builder<T extends ColumnBuilderBaseConfig<'string', 'PgCuid2'>> extends PgColumnBuilder<T> { static readonly [entityKind]: string; private length; constructor(name: T['name']); build<TTableName extends string>(table: AnyPgTable<{ name: TTableName; }>): PgCuid2<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 PgCuid2<T extends ColumnBaseConfig<'string', 'PgCuid2'>> extends PgColumn<T> { static readonly [entityKind]: string; private length; constructor(table: AnyPgTable<{ name: string; }>, config: ColumnBuilderRuntimeConfig<T extends { $type: infer U; } ? U : T['data'], PgCuid2Config>, length: number); getSQLType(): string; } declare function cuid2(): PgCuid2BuilderInitial<''>; declare function cuid2<TName extends string>(name: TName): PgCuid2BuilderInitial<TName>; export { PgCuid2, PgCuid2Builder, type PgCuid2BuilderInitial, type PgCuid2Config, cuid2 };