import type { PrimaryKey, AlternateKey, ForeignKey, Table } from "../types.ts"; import { type IfNotExistsTransition, ifNotExistsTransition, type WithForeignKeyColumnTransition, withForeignKeyColumnTransition, type WithOptionalColumnTransition, withOptionalColumnTransition, type WithPrimaryKeyColumnTransition, withPrimaryKeyColumnTransition, type WithRequiredColumnTransition, withRequiredColumnTransition, } from "../transitions/index.ts"; export interface CreateTemporaryTable< TPrimaryKey extends Record = Record, TAlternateKeys extends Record = Record, TForeignKeys extends Record = Record, > { table: Table; ifNotExists: IfNotExistsTransition; withPrimaryKeyColumn: WithPrimaryKeyColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >; withRequiredColumn: WithRequiredColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >; withOptionalColumn: WithOptionalColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >; withForeignKeyColumn: WithForeignKeyColumnTransition< TPrimaryKey, TAlternateKeys, TForeignKeys >; } export function createTemporaryTable< TPrimaryKey extends Record, TAlternateKeys extends Record, TForeignKeys extends Record, >( name: string, schema?: string, ): CreateTemporaryTable { const table = { name, schema, isTemporary: true, createIfNotExists: false, primaryKey: {}, alternateKeys: {}, foreignKeys: {}, } as Table; return { table, ifNotExists: ifNotExistsTransition(table), withPrimaryKeyColumn: withPrimaryKeyColumnTransition(table), withRequiredColumn: withRequiredColumnTransition(table), withOptionalColumn: withOptionalColumnTransition(table), withForeignKeyColumn: withForeignKeyColumnTransition(table), }; }