pg-json-schema-export

0.13.7 • Public • Published

pg-json-schema-export

NPM version Build status Dependency Status

Export a Postgres schema as JSON

Install

$ npm install pg-json-schema-export --save

Usage

var PostgresSchema = require('pg-json-schema-export');
var connection =
  user: 'postgres',
  password: '123',
  host: 'localhost',
  port: 5432,
  database: 'thedb'
};
PostgresSchema.toJSON(connection, 'public')
  .then(function (schemas) {
    // handle json object
  })
  .catch(function (error) {
    // handle error
  });

Output Format

The output format is for the most part named after the columns in information_schema.

Structure

  • schemas
    • views
      • columns
    • tables
      • columns
    • sequences

JSON

{
  "tables": {
    "user": {
      "obj_description": "This table has Users in it",
      "columns": {
        "name": {
          "data_type": "text",
          // ... more columns
        }
      }
    },
    // ... more tables
  },
  "constraints": {
    // column constraints, grouped by table
  },
  "sequences": {
    // column sequences, grouped by table
  }

I auto-generate some JSON during each CI build; those are uploaded as Github releases: https://github.com/tjwebb/pg-json-schema-export/releases/latest

API

.toJSON(connection, schema)

parameter description
connection connection string or object compatible with pg
schema the database schema to export

License

MIT

Package Sidebar

Install

npm i pg-json-schema-export

Weekly Downloads

96

Version

0.13.7

License

MIT

Last publish

Collaborators

  • tjwebb