diff --git a/API.md b/API.md index 157504b..3e1bd3f 100644 --- a/API.md +++ b/API.md @@ -15,8 +15,10 @@ Create a query builder object **Parameters** - `driverType` **String** The name of the database type, eg. mysql or pg -- `connObject` **Object** A connection object from the database library you are connecting with -- `connLib` **[String]** The name of the db connection library you are using, eg. mysql or mysql2. Optional if the same as driverType +- `connObject` **Object** A connection object from the database library + you are connecting with +- `connLib` **[String]** The name of the db connection library you are + using, eg. mysql or mysql2. Optional if the same as driverType Returns **QueryBuilder** The Query Builder object diff --git a/CHANGELOG.md b/CHANGELOG.md index 773adf5..81a7d81 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 3.2.0 * Added public `query` method for making arbitrary sql calls -* Added back tests for `node-query` adapter. Using this adapter with promises is not currently supported. +* Added back tests for `node-firebird` adapter. Using this adapter with promises is not currently supported. ## 3.1.0 * Added support for promises on query execution methods \ No newline at end of file diff --git a/docs/index.html b/docs/index.html index c781fdc..db802e2 100644 --- a/docs/index.html +++ b/docs/index.html @@ -305,14 +305,16 @@
  • Object connObject :
    -

    A connection object from the database library you are connecting with

    +

    A connection object from the database library + you are connecting with

  • [String] connLib :
    -

    The name of the db connection library you are using, eg. mysql or mysql2. Optional if the same as driverType

    +

    The name of the db connection library you are + using, eg. mysql or mysql2. Optional if the same as driverType

  • diff --git a/lib/Driver.js b/lib/Driver.js index 3d9b84d..cac0cd1 100755 --- a/lib/Driver.js +++ b/lib/Driver.js @@ -21,7 +21,9 @@ let Driver = { * @private */ _quote(str) { - return (helpers.isString(str) && ! (str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar))) + return (helpers.isString(str) + && ! (str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar)) + ) ? `${Driver.identifierStartChar}${str}${Driver.identifierEndChar}` : str; }, diff --git a/lib/NodeQuery.js b/lib/NodeQuery.js index 753956e..58d4652 100755 --- a/lib/NodeQuery.js +++ b/lib/NodeQuery.js @@ -23,8 +23,10 @@ class NodeQuery { * Create a query builder object * * @param {String} driverType - The name of the database type, eg. mysql or pg - * @param {Object} connObject - A connection object from the database library you are connecting with - * @param {String} [connLib] - The name of the db connection library you are using, eg. mysql or mysql2. Optional if the same as driverType + * @param {Object} connObject - A connection object from the database library + * you are connecting with + * @param {String} [connLib] - The name of the db connection library you are + * using, eg. mysql or mysql2. Optional if the same as driverType * @return {QueryBuilder} - The Query Builder object */ init(driverType, connObject, connLib) { diff --git a/lib/QueryBuilder.js b/lib/QueryBuilder.js index bc1865b..d097b2a 100755 --- a/lib/QueryBuilder.js +++ b/lib/QueryBuilder.js @@ -131,7 +131,8 @@ class QueryBuilderBase { * @return {Array} - modified state array */ _mixedSet(/* $letName, $valType, $key, [$val] */) { - let args = getArgs('$letName:string, $valType:string, $key:object|string|number, [$val]', arguments); + const argPattern = '$letName:string, $valType:string, $key:object|string|number, [$val]'; + let args = getArgs(argPattern, arguments); let obj = {}; @@ -784,7 +785,8 @@ class QueryBuilder extends QueryBuilderBase { * @return {void|Promise} - If no callback is passed, a promise is returned */ get(/* [table], [limit], [offset], [callback] */) { - let args = getArgs('[table]:string, [limit]:number, [offset]:number, [callback]:function', arguments); + const argPattern = '[table]:string, [limit]:number, [offset]:number, [callback]:function'; + let args = getArgs(argPattern, arguments); if (args.table) { this.from(args.table); diff --git a/lib/helpers.js b/lib/helpers.js index adc9c2b..76e2adf 100755 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -127,7 +127,8 @@ types.forEach(t => { * Determine whether a variable is of the type specified in the * function name, eg isNumber * - * Types available are Null, Undefined, Object, Array, String, Number, Boolean, Function, RegExp, NaN and Infinite + * Types available are Null, Undefined, Object, Array, String, Number, + * Boolean, Function, RegExp, NaN and Infinite * * @private * @param {mixed} o - The object to check its type diff --git a/test/adapters/mysql2_test.js b/test/adapters/mysql2_test.js index aad5562..791702b 100644 --- a/test/adapters/mysql2_test.js +++ b/test/adapters/mysql2_test.js @@ -1,6 +1,6 @@ 'use strict'; -const configFile = (process.env.CI) ? '../config-travis.json' : '../config.json'; +const configFile = (process.env.TRAVIS) ? '../config-travis.json' : '../config.json'; // Load the test base const reload = require('require-reload')(require); diff --git a/test/adapters/mysql_test.js b/test/adapters/mysql_test.js index 853c27d..b1d95d5 100644 --- a/test/adapters/mysql_test.js +++ b/test/adapters/mysql_test.js @@ -1,6 +1,6 @@ 'use strict'; -const configFile = (process.env.CI) ? '../config-travis.json' : '../config.json'; +const configFile = (process.env.TRAVIS) ? '../config-travis.json' : '../config.json'; // Load the test base const reload = require('require-reload')(require); diff --git a/test/adapters/node-firebird_test.js b/test/adapters/node-firebird_test.js index f53a5e5..a546466 100644 --- a/test/adapters/node-firebird_test.js +++ b/test/adapters/node-firebird_test.js @@ -1,59 +1,61 @@ 'use strict'; -// Load the test base -const path = require('path'); -const reload = require('require-reload')(require); -const testBase = reload('../base'); -const promisify = require('../../lib/promisify'); -const expect = reload('chai').expect; -const testRunner = testBase.testRunner; -const promiseTestRunner = testBase.promiseTestRunner; +(() => { + // Load the test base + const path = require('path'); + const reload = require('require-reload')(require); + const testBase = reload('../base'); + const promisify = require('../../lib/promisify'); + const expect = reload('chai').expect; + const testRunner = testBase.testRunner; + const promiseTestRunner = testBase.promiseTestRunner; -// Load the test config file -let adapterName = 'node-firebird'; -let Firebird = reload(adapterName); -const config = reload('../config.json')[adapterName]; -config.conn.database = path.join(__dirname, config.conn.database); -let nodeQuery = reload('../../lib/NodeQuery'); + // Load the test config file + let adapterName = 'node-firebird'; + let Firebird = reload(adapterName); + const config = reload('../config.json')[adapterName]; + config.conn.database = path.join(__dirname, config.conn.database); + let nodeQuery = reload('../../lib/NodeQuery'); -let qb = null; + let qb = null; -// Skip on TravisCi -if (process.env.CI || process.env.JENKINS_HOME) { - return; -} + // Skip on TravisCi + if (process.env.CI) { + return; + } -// Promisifying the connection seems to be the only way to get -// this test suite to run consistently. -promisify(Firebird.attach)(config.conn).then(db => { - qb = nodeQuery.init('firebird', db, adapterName); - suite('Firebird adapter tests -', () => { - test('nodeQuery.getQuery = nodeQuery.init', () => { - expect(nodeQuery.getQuery()) - .to.be.deep.equal(qb); - }); - test('insertBatch throws error', () => { - expect(() => { - qb.driver.insertBatch('create_test', []); - }).to.throw(Error, "Not Implemented"); - }); - /*--------------------------------------------------------------------------- - Callback Tests - ---------------------------------------------------------------------------*/ - testRunner(qb, (err, done) => { - expect(err).is.not.ok; - done(); - }); - /*--------------------------------------------------------------------------- - Promise Tests - ---------------------------------------------------------------------------*/ - /*qb.adapter.execute(qb.driver.truncate('create_test')).then(() => { - promiseTestRunner(qb); - });*/ - suiteTeardown(() => { - qb.end(); + // Promisifying the connection seems to be the only way to get + // this test suite to run consistently. + promisify(Firebird.attach)(config.conn).then(db => { + qb = nodeQuery.init('firebird', db, adapterName); + suite('Firebird adapter tests -', () => { + test('nodeQuery.getQuery = nodeQuery.init', () => { + expect(nodeQuery.getQuery()) + .to.be.deep.equal(qb); + }); + test('insertBatch throws error', () => { + expect(() => { + qb.driver.insertBatch('create_test', []); + }).to.throw(Error, 'Not Implemented'); + }); + /*--------------------------------------------------------------------------- + Callback Tests + ---------------------------------------------------------------------------*/ + testRunner(qb, (err, done) => { + expect(err).is.not.ok; + done(); + }); + /*--------------------------------------------------------------------------- + Promise Tests + ---------------------------------------------------------------------------*/ + /*qb.adapter.execute(qb.driver.truncate('create_test')).then(() => { + promiseTestRunner(qb); + });*/ + suiteTeardown(() => { + qb.end(); + }); }); + }).catch(err => { + throw new Error(err); }); -}).catch(err => { - throw new Error(err); -}); +})(); diff --git a/test/base/adapterCallbackTestRunner.js b/test/base/adapterCallbackTestRunner.js index ce874fa..4555cd0 100644 --- a/test/base/adapterCallbackTestRunner.js +++ b/test/base/adapterCallbackTestRunner.js @@ -1,5 +1,6 @@ 'use strict'; +// jscs:disable // Load the test base const chai = require('chai'); const chaiAsPromised = require('chai-as-promised'); diff --git a/test/base/adapterPromiseTestRunner.js b/test/base/adapterPromiseTestRunner.js index 0dbf97d..4ccc9da 100644 --- a/test/base/adapterPromiseTestRunner.js +++ b/test/base/adapterPromiseTestRunner.js @@ -1,5 +1,6 @@ 'use strict'; +// jscs:disable // Load the test base const chai = require('chai'); const chaiAsPromised = require('chai-as-promised'); diff --git a/test/base/tests.js b/test/base/tests.js index 6c43bf1..d4e3e3d 100644 --- a/test/base/tests.js +++ b/test/base/tests.js @@ -1,5 +1,6 @@ 'use strict'; +// jscs:disable module.exports = { 'Get tests -': { 'Get with function': { diff --git a/test/query-parser_test.js b/test/query-parser_test.js index ca2abde..f4d50e1 100644 --- a/test/query-parser_test.js +++ b/test/query-parser_test.js @@ -15,7 +15,8 @@ let State = require('../lib/State'); let state = new State(); let mixedSet = function mixedSet(/* $letName, $valType, $key, [$val] */) { - let args = getArgs('$letName:string, $valType:string, $key:object|string|number, [$val]', arguments); + const argPattern = '$letName:string, $valType:string, $key:object|string|number, [$val]'; + let args = getArgs(argPattern, arguments); let obj = {};