mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
44537bd15f
closes #6911 - update lodash to v4 - remove lodash.tostring override - remove lodash from greenkeeper ignore
43 lines
1.0 KiB
JavaScript
43 lines
1.0 KiB
JavaScript
var _ = require('lodash'),
|
|
db = require('../../../data/db'),
|
|
|
|
// private
|
|
doRaw,
|
|
|
|
// public
|
|
getTables,
|
|
getIndexes,
|
|
getColumns;
|
|
|
|
doRaw = function doRaw(query, fn) {
|
|
return db.knex.raw(query).then(function (response) {
|
|
return fn(response);
|
|
});
|
|
};
|
|
|
|
getTables = function getTables() {
|
|
return doRaw('select * from sqlite_master where type = "table"', function (response) {
|
|
return _.reject(_.map(response, 'tbl_name'), function (name) {
|
|
return name === 'sqlite_sequence';
|
|
});
|
|
});
|
|
};
|
|
|
|
getIndexes = function getIndexes(table) {
|
|
return doRaw('pragma index_list("' + table + '")', function (response) {
|
|
return _.flatten(_.map(response, 'name'));
|
|
});
|
|
};
|
|
|
|
getColumns = function getColumns(table) {
|
|
return doRaw('pragma table_info("' + table + '")', function (response) {
|
|
return _.flatten(_.map(response, 'name'));
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
getTables: getTables,
|
|
getIndexes: getIndexes,
|
|
getColumns: getColumns
|
|
};
|