pg-to-ts
Version:
Generate TypeScript-friendly interfaces and constants from (postgres) SQL database schema
56 lines (55 loc) • 2.04 kB
TypeScript
import PgPromise from 'pg-promise';
import _ from 'lodash';
import Options from './options';
import { ColumnDefinition, TableDefinition, ForeignKey } from './schemaInterfaces';
export declare function pgTypeToTsType(column: ColumnDefinition, customTypes: string[], options: Options): string;
interface Metadata {
schema: string;
enumTypes: Record<string, string[]>;
foreignKeys: {
[tableName: string]: {
[columnName: string]: ForeignKey;
};
};
tableToKeys: {
[tableName: string]: string;
};
columnComments: {
[tableName: string]: {
[columnName: string]: string;
};
};
tableComments: {
[tableName: string]: string;
};
}
export declare class PostgresDatabase {
db: PgPromise.IDatabase<unknown>;
metadata: Metadata | null;
connectionString: string;
constructor(connectionString: string);
static mapTableDefinitionToType(tableDefinition: TableDefinition, customTypes: string[], options: Options): TableDefinition;
query(queryString: string): Promise<any>;
/** Call this if you know the DB has changed underneath you, e.g. in a test. */
reset(): void;
getEnumTypes(schema?: string): Promise<Record<string, string[]>>;
getTableDefinition(tableName: string, tableSchema: string): Promise<TableDefinition>;
getTableTypes(tableName: string, tableSchema: string, options: Options): Promise<TableDefinition>;
getSchemaTables(schemaName: string): Promise<string[]>;
getPrimaryKeys(schemaName: string): Promise<{
[x: string]: string;
}>;
getColumnComments(schemaName: string): Promise<{
[x: string]: _.Dictionary<string>;
}>;
getTableComments(schemaName: string): Promise<_.Dictionary<string>>;
getForeignKeys(schemaName: string): Promise<{
[x: string]: _.Dictionary<{
table: string;
column: string;
}>;
}>;
getMeta(schemaName: string): Promise<Metadata>;
getDefaultSchema(): string;
}
export {};