Export a Postgres schema as JSON
$ npm install pg-json-schema-export --save
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
});
The output format is for the most part named after the columns in information_schema
.
- schemas
- views
- columns
- tables
- columns
- sequences
- views
{
"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
parameter | description |
---|---|
connection |
connection string or object compatible with pg |
schema |
the database schema to export |
MIT