shelving
Version:
Toolkit for using data in JavaScript.
53 lines (52 loc) • 3.4 kB
TypeScript
import type { Schema } from "../../schema/Schema.js";
import type { Data } from "../../util/data.js";
import type { Collection, Collections } from "../collection/Collection.js";
import type { SQLProvider } from "../provider/SQLProvider.js";
import { DBMigrator } from "./DBMigrator.js";
/** Column definition in a live SQL table. */
export type SQLTableColumn = {
readonly name: string;
readonly statement: string;
};
/** Existing SQL table schema keyed by column name. */
export type SQLTable = {
readonly columns: Readonly<Record<string, SQLTableColumn>>;
readonly name: string;
readonly sql?: string | undefined;
};
/** Generated SQL column mapped from a collection path. */
export type SQLColumn = {
readonly column: string;
readonly key: string;
readonly path: string;
};
/** Shared SQL migration logic based on schema diffing. */
export declare abstract class SQLMigrator<T extends SQLProvider = SQLProvider> extends DBMigrator<T> {
migrate(...collections: Collections<number>): Promise<void>;
getMigrations(...collections: Collections<number>): Promise<readonly string[]>;
getCreateTableQuery<T extends Data>(collection: Collection<string, number, T>): string;
getCreateTableColumns<T extends Data>(collection: Collection<string, number, T>): readonly SQLTableColumn[];
getGeneratedTableColumns<T extends Data>(collection: Collection<string, number, T>): readonly SQLTableColumn[];
protected getColumnMigrations(tableName: string, from: SQLTableColumn | undefined, to: SQLTableColumn | undefined): readonly string[];
protected getAlterColumnQueries(tableName: string, from: SQLTableColumn, to: SQLTableColumn): readonly string[];
protected getTableColumnDefinition({ name, statement }: SQLTableColumn): string;
protected getAddColumnQuery(tableName: string, column: SQLTableColumn): string;
protected getDropColumnQuery(tableName: string, columnName: string): string;
protected getTableMigrations<T extends Data>(collection: Collection<string, number, T>, table: SQLTable | undefined): readonly string[];
protected getIDColumn<T extends Data>(collection: Collection<string, number, T>): SQLTableColumn;
protected getDataColumn(): SQLTableColumn;
protected getGeneratedColumn<T extends Data>({ column, key, path }: SQLColumn, collection: Collection<string, number, T>): SQLTableColumn;
protected isSameColumn(from: SQLTableColumn, to: SQLTableColumn): boolean;
protected quoteIdentifier(value: string): string;
protected quoteString(value: string): string;
protected getGeneratedColumns<T extends Data>(collection: Collection<string, number, T>): readonly SQLColumn[];
protected getColumnName(key: string): string;
protected getJSONPath(key: string): string;
protected abstract getTables(): Promise<readonly string[]>;
protected abstract getTable(name: string): Promise<SQLTable | undefined>;
protected abstract getCreateTableSuffix<T extends Data>(collection: Collection<string, number, T>): string;
protected abstract getDataColumnDefinition(): string;
protected abstract getGeneratedColumnDefinition(columnName: string, path: string, definition: string): string;
protected abstract getIDColumnDefinition<T extends Data>(collection: Collection<string, number, T>): string;
protected definition<TValue>(schema: Schema<TValue>): string | undefined;
}