2014-05-15 22:29:42 -04:00
|
|
|
var _ = require('lodash'),
|
|
|
|
config = require('../../config');
|
2014-06-12 17:25:55 +02:00
|
|
|
|
|
|
|
function getTables() {
|
2014-05-15 22:29:42 -04:00
|
|
|
return config().database.knex.raw("select * from sqlite_master where type = 'table'").then(function (response) {
|
2014-06-12 17:25:55 +02:00
|
|
|
return _.reject(_.pluck(response, 'tbl_name'), function (name) {
|
|
|
|
return name === 'sqlite_sequence';
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIndexes(table) {
|
2014-05-15 22:29:42 -04:00
|
|
|
return config().database.knex.raw("pragma index_list('" + table + "')").then(function (response) {
|
2014-06-12 17:25:55 +02:00
|
|
|
|
|
|
|
return _.flatten(_.pluck(response, 'name'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getColumns(table) {
|
2014-05-15 22:29:42 -04:00
|
|
|
return config().database.knex.raw("pragma table_info('" + table + "')").then(function (response) {
|
2014-06-12 17:25:55 +02:00
|
|
|
return _.flatten(_.pluck(response, 'name'));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getTables: getTables,
|
|
|
|
getIndexes: getIndexes,
|
|
|
|
getColumns: getColumns
|
|
|
|
};
|