Something went wrong. Try again.
A fluent interface implementation for creating different SQLite queries in TypeScript without having to write SQL directly.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081import type { PrimaryKey, AlternateKey, ForeignKey, Table, SQLiteColumnTypes,} from "../types.ts";
import { type BuildTransition, buildTransition, withForeignKeyColumnTransition, withOptionalColumnTransition, type WithRequiredColumnTransition, withRequiredColumnTransition, type WithOptionalColumnTransition, type WithForeignKeyColumnTransition,} from "../transitions/index.ts";
export interface WithPrimaryKeyColumn< TPrimaryKey extends Record<string, PrimaryKey>, TAlternateKeys extends Record<string, AlternateKey>, TForeignKeys extends Record<string, ForeignKey>,> { table: Table<TPrimaryKey, TAlternateKeys, TForeignKeys>; build: BuildTransition; withRequiredColumn: WithRequiredColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >; withOptionalColumn: WithOptionalColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >; withForeignKeyColumn: WithForeignKeyColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >;}
export function withPrimaryKeyColumn< TPrimaryKey extends Record<string, PrimaryKey>, TAlternateKeys extends Record<string, AlternateKey>, TForeignKeys extends Record<string, ForeignKey>, const TName extends string, const TType extends SQLiteColumnTypes,>( table: Table<TPrimaryKey, TAlternateKeys, TForeignKeys>, name: TName, type: TType,): WithPrimaryKeyColumn< TPrimaryKey & Record<TName, PrimaryKey>, TAlternateKeys, TForeignKeys> { const new_table = { ...table, primaryKey: { [name]: { type, isPrimaryKey: true, }, }, } as Table< TPrimaryKey & Record<TName, PrimaryKey>, TAlternateKeys, TForeignKeys >;
return { table: new_table, build: buildTransition(new_table), withRequiredColumn: withRequiredColumnTransition(new_table), withOptionalColumn: withOptionalColumnTransition(new_table), withForeignKeyColumn: withForeignKeyColumnTransition(new_table), };}