0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-13 22:41:32 -05:00
ghost/core/server/data/utils/clients/sqlite3.js
Harry Wolff 469aaa398c Add jscs task to grunt file and clean up files to adhere to jscs rules.
resolves #1920

- updates all files to conform to style settings.
2014-09-17 21:44:29 -04:00

42 lines
1 KiB
JavaScript

var _ = require('lodash'),
config = require('../../../config/index'),
// private
doRaw,
// public
getTables,
getIndexes,
getColumns;
doRaw = function doRaw(query, fn) {
return config.database.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(_.pluck(response, 'tbl_name'), function (name) {
return name === 'sqlite_sequence';
});
});
};
getIndexes = function getIndexes(table) {
return doRaw('pragma index_list("' + table + '")', function (response) {
return _.flatten(_.pluck(response, 'name'));
});
};
getColumns = function getColumns(table) {
return doRaw('pragma table_info("' + table + '")', function (response) {
return _.flatten(_.pluck(response, 'name'));
});
};
module.exports = {
getTables: getTables,
getIndexes: getIndexes,
getColumns: getColumns
};