mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 11:34:24 +03:00
bcf5a1bc34
refs #9178 * Add eslint deps, remove old lint deps * Add eslint config, remove old lint configs * Config for server and tests are different * Tweaked rules to suit us * Fix linting in codebase - lots of indent changes. * Fix a real broken test
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
var _ = require('lodash'),
|
|
db = require('../../../data/db'),
|
|
|
|
// private
|
|
doRaw,
|
|
|
|
// public
|
|
getTables,
|
|
getIndexes,
|
|
getColumns;
|
|
|
|
doRaw = function doRaw(query, transaction, fn) {
|
|
if (!fn) {
|
|
fn = transaction;
|
|
transaction = null;
|
|
}
|
|
|
|
return (transaction || db.knex).raw(query).then(function (response) {
|
|
return fn(response);
|
|
});
|
|
};
|
|
|
|
getTables = function getTables(transaction) {
|
|
return doRaw('select * from sqlite_master where type = "table"', transaction, function (response) {
|
|
return _.reject(_.map(response, 'tbl_name'), function (name) {
|
|
return name === 'sqlite_sequence';
|
|
});
|
|
});
|
|
};
|
|
|
|
getIndexes = function getIndexes(table, transaction) {
|
|
return doRaw('pragma index_list("' + table + '")', transaction, function (response) {
|
|
return _.flatten(_.map(response, 'name'));
|
|
});
|
|
};
|
|
|
|
getColumns = function getColumns(table, transaction) {
|
|
return doRaw('pragma table_info("' + table + '")', transaction, function (response) {
|
|
return _.flatten(_.map(response, 'name'));
|
|
});
|
|
};
|
|
|
|
module.exports = {
|
|
getTables: getTables,
|
|
getIndexes: getIndexes,
|
|
getColumns: getColumns
|
|
};
|