mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
cddd23f926
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
29 lines
No EOL
852 B
JavaScript
29 lines
No EOL
852 B
JavaScript
var _ = require('lodash'),
|
|
config = require('../../config');
|
|
|
|
function getTables() {
|
|
return config().database.knex.raw("select * from sqlite_master where type = 'table'").then(function (response) {
|
|
return _.reject(_.pluck(response, 'tbl_name'), function (name) {
|
|
return name === 'sqlite_sequence';
|
|
});
|
|
});
|
|
}
|
|
|
|
function getIndexes(table) {
|
|
return config().database.knex.raw("pragma index_list('" + table + "')").then(function (response) {
|
|
|
|
return _.flatten(_.pluck(response, 'name'));
|
|
});
|
|
}
|
|
|
|
function getColumns(table) {
|
|
return config().database.knex.raw("pragma table_info('" + table + "')").then(function (response) {
|
|
return _.flatten(_.pluck(response, 'name'));
|
|
});
|
|
}
|
|
|
|
module.exports = {
|
|
getTables: getTables,
|
|
getIndexes: getIndexes,
|
|
getColumns: getColumns
|
|
}; |