diff --git a/lib/Adapter.js b/lib/Adapter.js index 5ab15bd..3381415 100755 --- a/lib/Adapter.js +++ b/lib/Adapter.js @@ -29,6 +29,6 @@ module.exports = class Adapter { * @return {void} */ close() { - this.instance.close(); + this.instance.end(); } }; \ No newline at end of file diff --git a/lib/QueryParser.js b/lib/QueryParser.js index 282eef9..9ae14ed 100644 --- a/lib/QueryParser.js +++ b/lib/QueryParser.js @@ -52,8 +52,9 @@ module.exports = class QueryParser { let output = []; // Return non-array matches - if (helpers.isNull(array)) return null; - if (helpers.isScalar(array) || helpers.isUndefined(array)) return output; + if (helpers.isNull(array)) { + return null; + } array.forEach(item => { output.push(item); @@ -157,9 +158,9 @@ module.exports = class QueryParser { // Filter explicit literals from lists of matches if (whereValues.indexOf(whereMap[key]) !== -1) { let value = whereMap[key]; - let identIndex = (helpers.isArray(parts.identifiers)) ? parts.identifiers.indexOf(value) : -1; + let identIndex = parts.identifiers.indexOf(value); let litIndex = (helpers.isArray(parts.literals)) ? parts.literals.indexOf(value) : -1; - let combIndex = (helpers.isArray(parts.combined)) ? parts.combined.indexOf(value) : -1; + let combIndex = parts.combined.indexOf(value); let funcIndex = (helpers.isArray(parts.functions)) ? parts.functions.indexOf(value) : -1; let inOutputArray = outputValues.indexOf(value) !== -1; @@ -190,16 +191,10 @@ module.exports = class QueryParser { if (combIndex !== -1 && funcIndex === -1) { // Make sure to skip functions when replacing values parts.combined[combIndex] = '?'; - - if (! inOutputArray) { - outputValues.push(value); - inOutputArray = true; - } } } // Filter false positive identifiers - parts.identifiers = parts.identifiers || []; parts.identifiers = parts.identifiers.filter(item => { let isInCombinedMatches = parts.combined.indexOf(item) !== -1; let isNotInBlackList = this.identifierBlacklist.indexOf(item.toLowerCase()) === -1; @@ -227,7 +222,7 @@ module.exports = class QueryParser { let litIndex = parts.combined.indexOf(lit); if (litIndex !== -1) { - parts.combined[litIndex] = (helpers.isArray(parts.operators)) ? '?' : '= ?'; + parts.combined[litIndex] = '?'; outputValues.push(lit); } }); diff --git a/lib/adapters/dblite.js b/lib/adapters/dblite.js index 9a4706e..371844e 100644 --- a/lib/adapters/dblite.js +++ b/lib/adapters/dblite.js @@ -16,4 +16,12 @@ module.exports = class dblite extends Adapter { let args = getArgs('sql:string, [params]:array, callback:function', arguments); this.instance.query(args.sql, args.params, args.callback); } + + /** + * Close the current database connection + * @return {void} + */ + close() { + this.instance.close(); + } }; \ No newline at end of file diff --git a/test/adapters/mysql2_test.js b/test/adapters/mysql2_test.js index e455a50..965f3c0 100644 --- a/test/adapters/mysql2_test.js +++ b/test/adapters/mysql2_test.js @@ -56,6 +56,6 @@ suite('Mysql2 adapter tests', () => { }); }); suiteTeardown(() => { - connection.end(); + qb.end(); }); }); \ No newline at end of file diff --git a/test/adapters/mysql_test.js b/test/adapters/mysql_test.js index ff1369f..adb2811 100644 --- a/test/adapters/mysql_test.js +++ b/test/adapters/mysql_test.js @@ -56,6 +56,6 @@ suite('Mysql adapter tests', () => { }); }); suiteTeardown(() => { - connection.end(); + qb.end(); }); }); \ No newline at end of file diff --git a/test/adapters/pg_test.js b/test/adapters/pg_test.js index e68d896..4d53d1b 100644 --- a/test/adapters/pg_test.js +++ b/test/adapters/pg_test.js @@ -15,7 +15,7 @@ let config = reload(configFile)[adapterName]; // Set up the connection let pg = reload(adapterName); let connection = new pg.Client(config.conn); -connection.connect(function(err) { +connection.connect(err => { if (err) { throw new Error(err); } @@ -59,6 +59,6 @@ suite('Pg adapter tests', () => { }); }); suiteTeardown(() => { - connection.end(); + qb.end(); }); }); \ No newline at end of file diff --git a/test/base_test.js b/test/base_test.js index 8530a31..fbec2c2 100644 --- a/test/base_test.js +++ b/test/base_test.js @@ -3,7 +3,8 @@ let expect = require('chai').expect, reload = require('require-reload')(require), glob = require('glob'), - nodeQuery = reload('../lib/NodeQuery'); + nodeQuery = reload('../lib/NodeQuery'), + Adapter = reload('../lib/Adapter'); suite('Base tests', () => { suite('Sanity check', () => { @@ -32,4 +33,11 @@ suite('Base tests', () => { nodeQuery.init('foo', {}, 'bar'); }).to.throw(Error, 'Selected driver (Foo) does not exist!'); }); + + test('Invalid adapter', () => { + expect(() => { + let a = new Adapter(); + a.execute(); + }).to.throw(Error, 'Correct adapter not defined for query execution'); + }); }); \ No newline at end of file