mysqldesc
Describe mysql database. Get table names, column specs as a json object.
Installation
npm install mysqldesc --save-dev
Usage
Describe database data.
var mysqldesc = require('mysqldesc'); // Mysql connect config.var config = { user: 'root', password: 'my_password', host: 'localhost', database: 'my_db'};// Desc connected databasemysqldesc(config, function (err, data) { console.log("structure=" + JSON.stringify(data, null, 4));});
This will result like:
structure = { // Tables in "my_db" database. "TEST_PERSON": { // Columns in "TEST_PERSON" table. "PersonID": { // Spec of "TEST_PERSON.PersonID" column. "Type": "int(11)", "Null": "YES", "Key": "", "Default": null, "Extra": "" }, "LastName": { "Type": "varchar(255)", "Null": "YES", "Key": "", "Default": null, "Extra": "" } }, "TEST_SHOP": { /*...*/ }};
API
Signature | Description |
---|---|
mysqldesc(config, callback) | Describe tables in the connected database. |
mysqldesc(config, databaseName, callback) | Describe tables in a specific database. |
mysqldesc(config, databaseName, tableName, callback) | Describe a specific table. |
mysqldesc.keyColumnUsage(config, callback) | Describe key column usage in the connected database. |
mysqldesc.keyColumnUsage(config, databaseName, callback) | Describe key column usage in a specific database. |
mysqldesc.keyColumnUsage(config, databaseName, tableName, callback) | Describe key column usage in a specific table. |
Tips
Connection Options
mysqldesc
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.