UNPKG

db-conn-pgsql

Version:

Database Connecton Postgres SQL

38 lines 1.33 kB
export class PgSqlDialect { async table(conn, table) { const sql = `select table_name as "TableName", column_name as "ColumnName", ordinal_position as "OrdinalPosition", column_default as "ColumnDefault", udt_name as "ColumnType", is_nullable as "IsNullable", character_maximum_length as "CharacterMaxiumLength", NUMERIC_PRECISION as "NumericPercision", NUMERIC_SCALE as "NumericScale", t4.description as "TableComment", t3.description as "ColumnComment" from information_schema.columns t1 inner join pg_class t2 on t2.relname = t1.table_name left join pg_description t3 on t3.objoid = t2.oid and t3.objsubid=t1.ordinal_position left join pg_description t4 on t4.objoid = t2.oid and t4.objsubid=0 where table_schema = 'public' and table_name = ? order by table_name, ordinal_position`; const rs = await conn.executeQuery(sql, [table]); const oTable = {}; oTable.name = table; oTable.fieldsOrder = []; oTable.fields = {}; for (const row of rs) { const fieldName = row['ColumnName']; oTable.fieldsOrder.push(fieldName); oTable.fields[fieldName] = {}; } return oTable; } ; quote() { return '"'; } ; } //# sourceMappingURL=PgSqlDialect.js.map