GithubHelp home page GithubHelp logo

tjwebb / pg-json-schema-export Goto Github PK

View Code? Open in Web Editor NEW
38.0 3.0 18.0 65 KB

Export Postgres schemas as JSON ( tables, constraints, sequences)

Home Page: https://www.npmjs.org/package/pg-json-schema-export

License: MIT License

JavaScript 92.71% SQLPL 7.29%

pg-json-schema-export's Introduction

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

pg-json-schema-export's People

Contributors

anuragagarwal561994 avatar tjwebb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pg-json-schema-export's Issues

Error: ENOENT, no such file or directory './sql/views.sql'

Hi,

Node couldn't load views.sql file within the sql directory.

Here's the console error log below:

bash-3.2$ node mgrt_pg_to_mongo.js

fs.js:427
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: ENOENT, no such file or directory './sql/views.sql'
    at Object.fs.openSync (fs.js:427:18)
    at Object.fs.readFileSync (fs.js:284:15)
    at Object.<anonymous> (/Users/charyorde/projects/nodescripts/node_modules/pg-json-schema-export/index.js:7:25)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/charyorde/projects/nodescripts/mgrt_pg_to_mongo.js:1:84)

Env:

  • node v0.10.25
  • OSX 8

some sequences are missing?

64           "column_default": "nextval(('accnt_accnt_id_seq'::text)::regclass)",

accnt_accnt_id_seq not in sequences list

Table name in uppercase

When the schema has table names with first letter in uppercase, an error message appear:

{"name":"error","length":106,"severity":"ERROR","code":"42P01","file":"namespace.c","line":"413","routine":"RangeVarGetRelidExtended"}

Searching for "postgresql 42P01", the conclusion is:
Unquoted identifiers are folded to lowercase, so if you created the
table with mixed-case letters then you'll have to quote the table
name. For more information see "Identifiers and Key Words" in the
"SQL Syntax" chapter of the documentation.

http://www.postgresql.org/message-id/[email protected]

Error with views

Hi,
I try to export my public schema to JSON but I have lot of views and I think you should exlude table_type VIEW from exporting.

image

because I have this error:
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.