Giter VIP home page Giter VIP logo

pg-tables-to-jsonschema's Introduction

pg-tables-to-jsonschema

NPM version

Npm Downloads

A command-line utility and module to turn postgresql tables into JSON Schemas. Uses pg-json-schema-export for the table to json conversion.

I wrote this module because I have a set of REST based backends using JSON Schema for their input and output validation. The tables provide the low level data interchange formats I use throughtout my code. So pairing this with my other jsonschema-to-typings utility gives me both code completion and hinting alongside jsonschema based validation.

DISCLAIMER: I wrote this module to fit my specific project needs. I may have missed a few column types. Also complex types like arrays and geospatial data have not been added. Feel free to fork or add pull requests for anything you are missing

Command-line usage

pgtables2jsonschema --pg-host localhost --pg-user admin --pg-password secret --pg-database my-db --pg-schema my_schema -b 'http://yourhost/schema/' -o test/

Calling with -h will provide you with all the possible options:

Usage: cli [options]

  Options:

    -V, --version                 output the version number
    --pg-host <value>             The postgresql host to connect to
    --pg-port <n>                 The postgresql host to connect to. Defaults to 5432
    --pg-database <value>         The postgresql database to connect to
    --pg-user <value>             The postgresql user to login with
    --pg-password <value>         The postgresql password to login with
    --pg-schema <value>           The postgresql schema to convert
    -i, --indent [size]           The indent size in spaces. Default: 2
    -o, --out [file]              Output folder. Default output is to STDOUT
    -b, --base-url [url]          The optional base url for the schema id
    -p, --additional-properties   Allow additional properties on final schema. Set option to allow properties. Default: false
    -t, --include-tables <value>  Comma separated list of tables to process. Default is all tables found
    -e, --exclude-tables <value>  Comma separated list of tables to exclude. Default is to not exclude any
    -u, --unwrap                  Unwraps the schema if only 1 is returned
    -h, --help                    output usage information

Code usage

You can use the schema converter module as follows:

var converter = require( "pg-tables-to-jsonschema" );

converter( {
    "pgHost":     "localhost"
,   "pgPort":     5432
,   "pgUser":     "admin"
,   "pgPassword": "secret"
,   "pgDatabase": "my_database"
,   "pgSchema":   "my_schema"
,   "baseUrl":    "http://yourhost/schema/"
,   "indent":     2
} )
.then( function( schemas )
{
  // Schema's is an array of json-schema objects
  //
  console.log( JSON.stringify( schemas, null, '  ' ) )
} )
.catch( function( error )
{
  console.error( 'Conversion failed', error );
} );

pg-tables-to-jsonschema's People

Contributors

laughedelic avatar qwerios avatar

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.