pg2json

Reads the schema of a postgres db

Usage no npm install needed!

<script type="module">
  import pg2json from 'https://cdn.skypack.dev/pg2json';
</script>

README

Promises/A+ logo

pg2json

This module loads postgres meta data and returns it as json.

Build Status

Usage

CLI

  1. create a config file:
{
    "charset": "utf8",
    "database": "heinzel",
    "host": "127.0.0.1",
    "user": "user",
    "password": "password"
}
  1. use the cli
node bin\cli.js -c configFile -o outputFile

use help (-h / -help) for more information 3. select desired table

Node module


var pg2json = require('pg2json');

//1. Setup connection
pg2json.connect({
    charset: 'utf8',
    database: 'test',
    host: '127.0.0.1',
    user: 'user',
    password: 'password'
});

//2. Get tables
pg2json.getTables()
    .then(onTablesRead)
    .fail(onError);

//3. Get columns
pg2json.getColumns('tableName')
    .then(onColumnsRead)
    .fail(onError);

//4. Get relations
pg2json.getRelations('tableName')
    .then(onRelationsRead)
    .fail(onError);