2016-02-12 14:56:27 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
db = require('../../../data/db'),
|
2014-07-10 19:10:00 +04:00
|
|
|
|
2014-09-10 08:06:24 +04:00
|
|
|
// private
|
2014-08-17 10:17:23 +04:00
|
|
|
doRaw,
|
2014-07-10 19:10:00 +04:00
|
|
|
|
2014-08-17 10:17:23 +04:00
|
|
|
// public
|
|
|
|
getTables,
|
|
|
|
getIndexes,
|
|
|
|
getColumns;
|
2014-07-10 19:10:00 +04:00
|
|
|
|
|
|
|
doRaw = function doRaw(query, fn) {
|
2016-02-12 14:56:27 +03:00
|
|
|
return db.knex.raw(query).then(function (response) {
|
2014-07-10 19:10:00 +04:00
|
|
|
return fn(response);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
getTables = function getTables() {
|
|
|
|
return doRaw('select * from sqlite_master where type = "table"', function (response) {
|
2016-06-11 21:23:27 +03:00
|
|
|
return _.reject(_.map(response, 'tbl_name'), function (name) {
|
2014-07-10 19:10:00 +04:00
|
|
|
return name === 'sqlite_sequence';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
getIndexes = function getIndexes(table) {
|
|
|
|
return doRaw('pragma index_list("' + table + '")', function (response) {
|
2016-06-11 21:23:27 +03:00
|
|
|
return _.flatten(_.map(response, 'name'));
|
2014-07-10 19:10:00 +04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
getColumns = function getColumns(table) {
|
|
|
|
return doRaw('pragma table_info("' + table + '")', function (response) {
|
2016-06-11 21:23:27 +03:00
|
|
|
return _.flatten(_.map(response, 'name'));
|
2014-07-10 19:10:00 +04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getTables: getTables,
|
|
|
|
getIndexes: getIndexes,
|
|
|
|
getColumns: getColumns
|
2014-09-10 08:06:24 +04:00
|
|
|
};
|