JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q45655F
  • License MIT

Creates and maintains a SQL table structure

Package Exports

  • json-schema-table
  • json-schema-table/src/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-schema-table) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

json-schema-table NPM version Dependency Status CircleCI

Creates and maintains a SQL table structure equivalent to a json schema definition. For MSSQL and Postgres

First you create all your tables and then syncronizes then with each other to create the references. You can sync whenever you modify your json schema

Install

$ npm install --save json-schema-table

Usage

var jsonSchemaTable = require('json-schema-table');
var pg = require('pg-cr-layer');
var studentSchema = require('./student.json');
var classSchema = require('./class.json');

// initialize and connect to a database

var studentTable = jsonSchemaTable('person', studentSchema, {db: pg});
var classTable = jsonSchemaTable('student', classSchema, {db: pg});

// First create then sync to build the references
studentTable.create().then(function() {
    return classTable.create();
}).then(function() {
    return studentTable.sync();
}).then(function() {
    return classTable.sync();
}).catch(function(error) {
    console.log(error);
});

For the db connection you can use mssql-cr-layer or pg-cr-layer

To more details take a look at the tests

License

MIT © Andre Gloria