mysqlspec
Generate JSON schema from mysql tables.
Installation
npm install mysqlspec --save-dev
Usage
Describe database data.
var mysqlspec = require('mysqlspec'); // Mysql connect config.var config = { user: 'root', password: 'my_password', host: 'localhost', database: 'my_db'};// Get spec for connected databasemysqlspec(config, function (err, schema) { console.log("schema=" + JSON.stringify(schema, null, 4));});
This will result like:
schema = { // Schemas for in "my_db" database. 'TEST_SHOP': { // Schema for in "my_db.TEST_SHOP" table. name: 'my_db.TEST_SHOP', properties: { id: {type: 'integer', maxLength: 5}, article: {type: 'integer', maxLength: 4}, dealer: {type: 'string', maxLength: 20}, price: {type: 'number'} }, required: ['id', 'article', 'dealer', 'price'], additionalProperties: false }, 'TEST_PERSON':{ /**...*/ }};
API
Signature | Description |
---|---|
mysqlspec(config, callback) | Get JSON schem for tables in a database. |
mysqlspec(config, databaseName, callback) | Get JSON schem for tables in a database. |
mysqlspec(config, databaseName, tableName, callback) | Get JSON schem for a specific table. |
Tips
Connection Options
mysqlspec
uses node-mysql as connector.
For more advanced setting, see the node-mysql documents about Connection options
License
This software is released under the MIT License.