Skip to content
This repository has been archived by the owner on Mar 4, 2019. It is now read-only.

Commit

Permalink
Update tables.js (#367)
Browse files Browse the repository at this point in the history
* Update tables.js

better use of sql query files.

* Update tables.js

fixing semicolon.
  • Loading branch information
vitaly-t authored and dmfay committed May 26, 2017
1 parent e8b3d50 commit af07989
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/loader/tables.js
Expand Up @@ -4,16 +4,19 @@ const co = require('co');
const path = require('path');
const pgp = require('pg-promise');

exports = module.exports = co.wrap(function* (driver, config) {
let tableSql = path.resolve(__dirname, '../scripts/tables.sql');
let parameters = [config.allowedSchemas, config.blacklist, config.exceptions];
function sql(file) {
var fullPath = path.join(__dirname, '../scripts/', file);
return new pgp.QueryFile(fullPath, {minify: true});
}

// ONLY allow whitelisted items:
if (config.whitelist) {
tableSql = path.resolve(__dirname, '../scripts/tables-whitelist.sql');
parameters = [config.whitelist];
}
let tableSql = sql('tables.sql');
let tableWhiteListSql = sql('tables-whitelist.sql');

return yield driver.query(new pgp.QueryFile(tableSql), parameters);
exports = module.exports = co.wrap(function* (driver, config) {
if(config.whitelist) {
return yield driver.query(tableWhiteListSql, [config.whitelist]);
} else {
return yield driver.query(tableSql, [config.allowedSchemas, config.blacklist, config.exceptions]);
}
});

0 comments on commit af07989

Please sign in to comment.