1.1.4 • Published 4 years ago

@tarkalabs/pg-db-utils v1.1.4

Weekly downloads
2
License
Apache-2.0
Repository
-
Last release
4 years ago

@tarkalabs/pg-db-utils

Database utility functions for querying the abstract structure of a postgresql database

Install


$ npm install @tarkalabs/pg-db-utils


Documentation


Features

  • 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

Exported Members

  • 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"

Example

Connecting and Getting the Structure

function() => {
    Connection.setup({
      label: "Localhost",
      host: "127.0.0.1",
      user:"postgres",
      password:"postgres",
      port:5432,
      database:"my_db_name"
    });

    const result = await getStructure();

Accessing data from the ErdModel

    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);

1.1.4

4 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.2

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago