2014-05-15 21:29:42 -05:00
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../../config');
|
2014-06-12 10:25:55 -05:00
|
|
|
|
|
|
|
function getTables() {
|
2014-05-15 21:29:42 -05:00
|
|
|
return config().database.knex.raw('show tables').then(function (response) {
|
2014-06-12 10:25:55 -05:00
|
|
|
return _.flatten(_.map(response[0], function (entry) {
|
|
|
|
return _.values(entry);
|
|
|
|
}));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIndexes(table) {
|
2014-05-15 21:29:42 -05:00
|
|
|
return config().database.knex.raw('SHOW INDEXES from ' + table).then(function (response) {
|
2014-06-12 10:25:55 -05:00
|
|
|
return _.flatten(_.pluck(response[0], 'Key_name'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getColumns(table) {
|
2014-05-15 21:29:42 -05:00
|
|
|
return config().database.knex.raw('SHOW COLUMNS FROM ' + table).then(function (response) {
|
2014-06-12 10:25:55 -05:00
|
|
|
return _.flatten(_.pluck(response[0], 'Field'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getTables: getTables,
|
|
|
|
getIndexes: getIndexes,
|
|
|
|
getColumns: getColumns
|
|
|
|
};
|