import DB from "./../DB"; import DataType from "./ColumnDataType"; export interface IColumns { [index: string]: IColumnInfo; } export interface IColumnInfo { type: DataType; isNullable: boolean; } export default (db: DB) => async (schemaName: string, tableName: string) => { const info: INFORMATION_SCHEMA_FIELDS[] = await db.query( `select * from information_schema.columns where table_schema = ? and table_name = ?`, [schemaName, tableName], ); const columns: IColumns = {}; for (const col of info) { columns[col.COLUMN_NAME] = { type: col.DATA_TYPE, isNullable: col.IS_NULLABLE === "yes" ? true : false }; } return columns; }; // tslint:disable-next-line:class-name export interface INFORMATION_SCHEMA_FIELDS { TABLE_CATALOG: string; TABLE_SCHEMA: string; TABLE_NAME: string; COLUMN_NAME: string; COLUMN_DEFAULT?: string; IS_NULLABLE: string; DATA_TYPE: DataType; CHARACTER_MAXIMUM_LENGTH?: number; CHARACTER_OCTET_LENGTH?: number; NUMERIC_SCALE?: number; DATETIME_PRECISION?: string; CHARACTER_SET_NAME?: string; COLLATION_NAME?: string; COLUMN_TYPE: string; COLUMN_KEY: string; EXTRA: string; PRIVILEGES: string; COLUMN_COMMENT: string; GENERATION_EXPRESSION: string; }