Fix reference to Helpers, other updates

This commit is contained in:
Timothy Warren 2017-02-28 16:11:34 -05:00
parent 26febfd7ab
commit a5eb0795c9
10 changed files with 42 additions and 40 deletions

View File

@ -1,11 +1,11 @@
before_script: before_script:
# Install dependencies # Install dependencies
- bash test/docker_install.sh > /dev/null - bash test/docker_install.sh > /dev/null
- npm install - yarn
services: services:
- mysql:latest - mariadb:latest
- postgres:latest - postgres: alpine
variables: variables:
MYSQL_ROOT_PASSWORD: foo-bar-baz MYSQL_ROOT_PASSWORD: foo-bar-baz
@ -23,9 +23,9 @@ cache:
- node_modules/ - node_modules/
test:6: test:6:
image: node:6 image: node:6-alpine
script: npm run test script: npm run test
test:latest: test:latest:
image: node:latest image: node:alpine
script: npm run test script: npm run test

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const helpers = require('./helpers'); const Helpers = require('./Helpers');
/** /**
* Base Database Driver * Base Database Driver
@ -21,7 +21,7 @@ const Driver = {
* @private * @private
*/ */
_quote (str) { _quote (str) {
return (helpers.isString(str) && return (Helpers.isString(str) &&
!(str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar)) !(str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar))
) )
? `${Driver.identifierStartChar}${str}${Driver.identifierEndChar}` ? `${Driver.identifierStartChar}${str}${Driver.identifierEndChar}`
@ -39,7 +39,7 @@ const Driver = {
limit (sql, limit, offset) { limit (sql, limit, offset) {
sql += ` LIMIT ${limit}`; sql += ` LIMIT ${limit}`;
if (helpers.isNumber(offset)) { if (Helpers.isNumber(offset)) {
sql += ` OFFSET ${offset}`; sql += ` OFFSET ${offset}`;
} }
@ -79,7 +79,7 @@ const Driver = {
// Handle commas // Handle commas
if (str.includes(',')) { if (str.includes(',')) {
let parts = str.split(',').map(helpers.stringTrim); let parts = str.split(',').map(Helpers.stringTrim);
str = parts.map(Driver.quoteIdentifiers).join(','); str = parts.map(Driver.quoteIdentifiers).join(',');
} }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const helpers = require('./helpers'); const Helpers = require('./Helpers');
const QueryParser = require('./QueryParser'); const QueryParser = require('./QueryParser');
const State = require('./State'); const State = require('./State');
@ -34,7 +34,7 @@ class QueryBuilderBase {
['queryMap', 'groupString', 'orderString', 'havingMap'].forEach(clause => { ['queryMap', 'groupString', 'orderString', 'havingMap'].forEach(clause => {
let param = this.state[clause]; let param = this.state[clause];
if (!helpers.isScalar(param)) { if (!Helpers.isScalar(param)) {
Object.keys(param).forEach(part => { Object.keys(param).forEach(part => {
sql += param[part].conjunction + param[part].string; sql += param[part].conjunction + param[part].string;
}); });
@ -44,7 +44,7 @@ class QueryBuilderBase {
}); });
// Append the limit, if it exists // Append the limit, if it exists
if (helpers.isNumber(this.state.limit)) { if (Helpers.isNumber(this.state.limit)) {
sql = this.driver.limit(sql, this.state.limit, this.state.offset); sql = this.driver.limit(sql, this.state.limit, this.state.offset);
} }
@ -132,10 +132,10 @@ class QueryBuilderBase {
_mixedSet (letName, valType, key, val) { _mixedSet (letName, valType, key, val) {
let obj = {}; let obj = {};
if (helpers.isScalar(key) && !helpers.isUndefined(val)) { if (Helpers.isScalar(key) && !Helpers.isUndefined(val)) {
// Convert key/val pair to a simple object // Convert key/val pair to a simple object
obj[key] = val; obj[key] = val;
} else if (helpers.isScalar(key) && helpers.isUndefined(val)) { } else if (Helpers.isScalar(key) && Helpers.isUndefined(val)) {
// If just a string for the key, and no value, create a simple object with duplicate key/val // If just a string for the key, and no value, create a simple object with duplicate key/val
obj[key] = key; obj[key] = key;
} else { } else {
@ -165,9 +165,9 @@ class QueryBuilderBase {
_fixConjunction (conj) { _fixConjunction (conj) {
let lastItem = this.state.queryMap[this.state.queryMap.length - 1]; let lastItem = this.state.queryMap[this.state.queryMap.length - 1];
let conjunctionList = helpers.arrayPluck(this.state.queryMap, 'conjunction'); let conjunctionList = Helpers.arrayPluck(this.state.queryMap, 'conjunction');
if (this.state.queryMap.length === 0 || (!helpers.regexInArray(conjunctionList, /^ ?WHERE/i))) { if (this.state.queryMap.length === 0 || (!Helpers.regexInArray(conjunctionList, /^ ?WHERE/i))) {
conj = ' WHERE '; conj = ' WHERE ';
} else if (lastItem.type === 'groupStart') { } else if (lastItem.type === 'groupStart') {
conj = ''; conj = '';

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const XRegExp = require('xregexp'); const XRegExp = require('xregexp');
const helpers = require('./helpers'); const Helpers = require('./Helpers');
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -59,7 +59,7 @@ class QueryParser {
let output = []; let output = [];
// Return non-array matches // Return non-array matches
if (helpers.isNull(array)) { if (Helpers.isNull(array)) {
return null; return null;
} }
@ -123,7 +123,7 @@ class QueryParser {
// Quote the identifiers // Quote the identifiers
parts.combined.forEach((part, i) => { parts.combined.forEach((part, i) => {
if (parts.identifiers.indexOf(part) !== -1 && !helpers.isNumber(part)) { if (parts.identifiers.indexOf(part) !== -1 && !Helpers.isNumber(part)) {
parts.combined[i] = this.driver.quoteIdentifiers(part); parts.combined[i] = this.driver.quoteIdentifiers(part);
} }
}); });
@ -166,9 +166,9 @@ class QueryParser {
if (whereValues.indexOf(whereMap[key]) !== -1) { if (whereValues.indexOf(whereMap[key]) !== -1) {
let value = whereMap[key]; let value = whereMap[key];
let identIndex = parts.identifiers.indexOf(value); let identIndex = parts.identifiers.indexOf(value);
let litIndex = (helpers.isArray(parts.literals)) ? parts.literals.indexOf(value) : -1; let litIndex = (Helpers.isArray(parts.literals)) ? parts.literals.indexOf(value) : -1;
let combIndex = parts.combined.indexOf(value); let combIndex = parts.combined.indexOf(value);
let funcIndex = (helpers.isArray(parts.functions)) ? parts.functions.indexOf(value) : -1; let funcIndex = (Helpers.isArray(parts.functions)) ? parts.functions.indexOf(value) : -1;
let inOutputArray = outputValues.indexOf(value) !== -1; let inOutputArray = outputValues.indexOf(value) !== -1;
// Remove the identifier in question, // Remove the identifier in question,
@ -210,7 +210,7 @@ class QueryParser {
}, this); }, this);
// Quote identifiers // Quote identifiers
if (helpers.isArray(parts.identifiers)) { if (Helpers.isArray(parts.identifiers)) {
parts.identifiers.forEach(ident => { parts.identifiers.forEach(ident => {
let index = parts.combined.indexOf(ident); let index = parts.combined.indexOf(ident);
if (index !== -1) { if (index !== -1) {
@ -224,7 +224,7 @@ class QueryParser {
// This should only apply to literal values that are not // This should only apply to literal values that are not
// explicitly mapped to values, but have to be parsed from // explicitly mapped to values, but have to be parsed from
// a where condition, // a where condition,
if (helpers.isArray(parts.literals)) { if (Helpers.isArray(parts.literals)) {
parts.literals.forEach(lit => { parts.literals.forEach(lit => {
let litIndex = parts.combined.indexOf(lit); let litIndex = parts.combined.indexOf(lit);

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const helpers = require('./helpers'); const Helpers = require('./Helpers');
/** /**
* Query result object * Query result object
@ -25,7 +25,7 @@ class Result {
if ( if (
this._columns.length === 0 && this._columns.length === 0 &&
this._rows.length > 0 && this._rows.length > 0 &&
helpers.isObject(rows[0]) Helpers.isObject(rows[0])
) { ) {
this.columns = Object.keys(rows[0]); this.columns = Object.keys(rows[0]);
} }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
let helpers = require('../helpers'); let Helpers = require('../Helpers');
/** /**
* Driver for Firebird databases * Driver for Firebird databases
@ -24,7 +24,7 @@ module.exports = (() => {
driver.limit = (origSql, limit, offset) => { driver.limit = (origSql, limit, offset) => {
let sql = `FIRST ${limit}`; let sql = `FIRST ${limit}`;
if (helpers.isNumber(offset)) { if (Helpers.isNumber(offset)) {
sql += ` SKIP ${offset}`; sql += ` SKIP ${offset}`;
} }

View File

@ -8,7 +8,7 @@
module.exports = (() => { module.exports = (() => {
delete require.cache[require.resolve('../Driver')]; delete require.cache[require.resolve('../Driver')];
const driver = require('../Driver'); const driver = require('../Driver');
const helpers = require('../helpers'); const Helpers = require('../Helpers');
driver.identifierStartChar = '['; driver.identifierStartChar = '[';
driver.identifierEndChar = ']'; driver.identifierEndChar = ']';

View File

@ -8,7 +8,7 @@
module.exports = (() => { module.exports = (() => {
delete require.cache[require.resolve('../Driver')]; delete require.cache[require.resolve('../Driver')];
const driver = require('../Driver'); const driver = require('../Driver');
const helpers = require('../helpers'); const Helpers = require('../Helpers');
driver.identifierStartChar = '`'; driver.identifierStartChar = '`';
driver.identifierEndChar = '`'; driver.identifierEndChar = '`';
@ -22,7 +22,7 @@ module.exports = (() => {
* @return {String} - Modified SQL statement * @return {String} - Modified SQL statement
*/ */
driver.limit = (sql, limit, offset) => { driver.limit = (sql, limit, offset) => {
sql += (helpers.isNumber(offset)) sql += (Helpers.isNumber(offset))
? ` LIMIT ${offset},${limit}` ? ` LIMIT ${offset},${limit}`
: ` LIMIT ${limit}`; : ` LIMIT ${limit}`;

View File

@ -37,15 +37,9 @@
}, },
"main": "lib/NodeQuery.js", "main": "lib/NodeQuery.js",
"dependencies": { "dependencies": {
"dblite": "~0.7.6",
"getargs": "~0.0.8", "getargs": "~0.0.8",
"glob": "^7.0.3", "glob": "^7.0.3",
"mysql2": "^1.0.0-rc.1",
"node-firebird": "^0.7.5",
"pg": "^6.0.0",
"require-reload": "~0.2.2", "require-reload": "~0.2.2",
"sqlite3": "^3.1.8",
"tedious": "^1.14.0",
"xregexp": "^3.0.0" "xregexp": "^3.0.0"
}, },
"devDependencies": { "devDependencies": {
@ -57,7 +51,7 @@
"happiness": "^7.1.2", "happiness": "^7.1.2",
"jest": "^19.0.2", "jest": "^19.0.2",
"jsdoc": "^3.4.3", "jsdoc": "^3.4.3",
"npm-run-all": "^3.0.0", "npm-run-all": "^4.0.2",
"nsp": "^2.2.1" "nsp": "^2.2.1"
}, },
"license": "MIT", "license": "MIT",
@ -89,5 +83,13 @@
"lint:src": "eslint ./lib", "lint:src": "eslint ./lib",
"lint:tests": "eslint ./test", "lint:tests": "eslint ./test",
"test": "jest" "test": "jest"
},
"peerDependencies": {
"dblite": "^0.7.8",
"mysql2": "^1.2.0",
"node-firebird": "^0.8.1",
"pg-native": "^1.10.0",
"sqlite3": "^3.1.8",
"tedious": "^1.14.0"
} }
} }

View File

@ -3,7 +3,7 @@
const expect = require('chai').expect; const expect = require('chai').expect;
// Use the base driver as a mock for testing // Use the base driver as a mock for testing
const helpers = require('../lib/helpers'); const Helpers = require('../lib/Helpers');
const driver = require('../lib/Driver'); const driver = require('../lib/Driver');
const P = require('../lib/QueryParser'); const P = require('../lib/QueryParser');
@ -17,10 +17,10 @@ let state = new State();
let mixedSet = function mixedSet (letName, valType, key, val) { let mixedSet = function mixedSet (letName, valType, key, val) {
let obj = {}; let obj = {};
if (helpers.isScalar(key) && !helpers.isUndefined(val)) { if (Helpers.isScalar(key) && !Helpers.isUndefined(val)) {
// Convert key/val pair to a simple object // Convert key/val pair to a simple object
obj[key] = val; obj[key] = val;
} else if (helpers.isScalar(key) && helpers.isUndefined(val)) { } else if (Helpers.isScalar(key) && Helpers.isUndefined(val)) {
// If just a string for the key, and no value, create a simple object with duplicate key/val // If just a string for the key, and no value, create a simple object with duplicate key/val
obj[key] = key; obj[key] = key;
} else { } else {