Database utility functions for querying the abstract structure of a postgresql database
$ npm install @tarkalabs/pg-db-utils
- Compatible with typescript
- Provides a simple Connection class for quick and easy sql queries
- Returns structure of a database that can be used to generate ER Diagrams
- Structure also provides a tree object which can be used for tree views
- getStructure()
- This function returns a JSON object that includes linked maps for every table in the selected database
- The JSON object is type ErdModel from "pg-db-utils/structure/interfaces"
function() => {
Connection.setup({
label: "Localhost",
host: "127.0.0.1",
user:"postgres",
password:"postgres",
port:5432,
database:"my_db_name"
});
const result = await getStructure();
const erdModel = await getStructure();
erdModel.tree.schemas.forEach(schema => {
str += schema.schemaName + "\n";
schema.tables.forEach(table => {
str += "\t- " + table.tableName + "\n";
table.columns.forEach(column => {
str += "\t\t- " + column.columnName + " : " + column.data_type + ((column.pk)? " pk": "") + ((column.fk)? " fk": "") + "\n";
});
});
});
console.log(str);