UNPKG

sqlite3orm

Version:

ORM for sqlite3 and TypeScript/JavaScript

110 lines (109 loc) 3.01 kB
import { SqlDatabase } from '../core'; import { TableOpts } from './decorators'; import { Table } from './Table'; /** * A singleton holding the database schema definitions * * @export * @class Schema */ export declare class Schema { /** * The one and only Schema instance * * @static */ static schema: Schema; private readonly mapNameToTable; private _dateInMilliSeconds?; get dateInMilliSeconds(): boolean; set dateInMilliSeconds(val: boolean); /** * Creates an instance of Schema. */ constructor(); /** * lookup table definition for given table name * * @param name - The name of the table * @returns The table definition or undefined */ hasTable(name: string): Table | undefined; /** * get a table definition * * @param name - The name of the table * @returns The table definition */ getTable(name: string): Table; /** * add a table definition * * @param table - The table definition * @returns The table definition */ getOrAddTable(name: string, opts: TableOpts): Table; /** * delete a table definition * * @param table - The table definition */ deleteTable(name: string): void; /** * get array of table definitions * * @returns The table definitions */ getAllTables(): Table[]; /** * create a table in the database * * @param sqldb - The db connection * @param name - The name of the table * @returns A promise */ createTable(sqldb: SqlDatabase, name: string, force?: boolean): Promise<void>; /** * drop a table from the database * * @param sqldb - The db connection * @param name - The name of the table * @returns A promise */ dropTable(sqldb: SqlDatabase, name: string): Promise<void>; /** * add a column/field to a database table * * @param sqldb - The db connection * @param tableName - The name of the table * @param colName - The name of the column * @returns A promise */ alterTableAddColumn(sqldb: SqlDatabase, tableName: string, colName: string): Promise<void>; /** * create an index in the database * * @param sqldb - The db connection * @param tableName - The name of the table * @param idxName - The name of the index * @param [unique] - create unique index * @returns A promise */ createIndex(sqldb: SqlDatabase, tableName: string, idxName: string, unique?: boolean): Promise<void>; /** * drop a table from the database * * @param sqldb - The db connection * @param tableName - The name of the table * @param idxName - The name of the index * @returns A promise */ dropIndex(sqldb: SqlDatabase, tableName: string, idxName: string): Promise<void>; } /** * get the Schema singleton * * @export * @returns {Schema} */ export declare function schema(): Schema;