import {Connection} from '../connection/Connection' import {Awaitable} from '../../util' import {TableBuilder} from './TableBuilder' /** * Represents a SQL-schema implementation. */ export abstract class Schema { constructor( /** The SQL connection to execute against. */ protected readonly connection: Connection, ) { } /** * Resolve true if the schema has a table with the given name. * @param name */ public abstract hasTable(name: string): Awaitable /** * Resolve true if the schema table with the given name has a column with the given name. * @param table * @param name */ public abstract hasColumn(table: string, name: string): Awaitable /** * Resolve true if the schema table with the given name has all the specified columns. * @param table * @param name */ public abstract hasColumns(table: string, name: string[]): Awaitable /** * Get a TableBuilder instance for a table on the schema. * @param table */ public abstract table(table: string): Awaitable /** * Apply the table to the schema. * @param schema */ public async commit(schema: TableBuilder): Promise { const query = this.connection .dialect() .renderCommitSchemaTransaction(schema) await this.connection.query(query) } }