Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrglo/json-schema-table
Creates and maintains a SQL table structure
https://github.com/andrglo/json-schema-table
Last synced: 4 days ago
JSON representation
Creates and maintains a SQL table structure
- Host: GitHub
- URL: https://github.com/andrglo/json-schema-table
- Owner: andrglo
- License: mit
- Created: 2015-08-13T20:09:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-24T18:30:43.000Z (3 months ago)
- Last Synced: 2024-12-11T04:42:00.113Z (12 days ago)
- Language: JavaScript
- Homepage:
- Size: 727 KB
- Stars: 29
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# json-schema-table [![NPM version][npm-image]][npm-url] [![Dependency Status][daviddm-image]][daviddm-url] [![CircleCI](https://circleci.com/gh/andrglo/json-schema-table.svg?style=svg)](https://circleci.com/gh/andrglo/json-schema-table)
> Creates and maintains a SQL table structure equivalent to a
json schema definition. For MSSQL and PostgresFirst 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
```sh
$ npm install --save json-schema-table
```## Usage
```js
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](https://github.com/andrglo/mssql-cr-layer)
or [pg-cr-layer](https://github.com/andrglo/pg-cr-layer)To more details take a look at the tests
## License
MIT © [Andre Gloria](andrglo.com)
[npm-image]: https://badge.fury.io/js/json-schema-table.svg
[npm-url]: https://npmjs.org/package/json-schema-table
[daviddm-image]: https://david-dm.org/andrglo/json-schema-table.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/andrglo/json-schema-table