0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/server/data/utils/mysql.js
Harry Wolff cddd23f926 Only reference model properties through the models module.
This frees us up to enforce one single point of access, thus paving
the way towards allowing us to initialize the models at are request,
and not when it's require().

addresses #2170
2014-07-10 08:04:32 -04:00

28 lines
No EOL
789 B
JavaScript

var _ = require('lodash'),
config = require('../../config');
function getTables() {
return config().database.knex.raw('show tables').then(function (response) {
return _.flatten(_.map(response[0], function (entry) {
return _.values(entry);
}));
});
}
function getIndexes(table) {
return config().database.knex.raw('SHOW INDEXES from ' + table).then(function (response) {
return _.flatten(_.pluck(response[0], 'Key_name'));
});
}
function getColumns(table) {
return config().database.knex.raw('SHOW COLUMNS FROM ' + table).then(function (response) {
return _.flatten(_.pluck(response[0], 'Field'));
});
}
module.exports = {
getTables: getTables,
getIndexes: getIndexes,
getColumns: getColumns
};