You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/orm/schema/Schema.ts

52 lines
1.4 KiB

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<boolean>
/**
* 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<boolean>
/**
* 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<boolean>
/**
* Get a TableBuilder instance for a table on the schema.
* @param table
*/
public abstract table(table: string): Awaitable<TableBuilder>
/**
* Apply the table to the schema.
* @param schema
*/
public async commit(schema: TableBuilder): Promise<void> {
const query = this.connection
.dialect()
.renderCommitSchemaTransaction(schema)
await this.connection.query(query)
}
}