Fix reference to Helpers, other updates
This commit is contained in:
parent
26febfd7ab
commit
a5eb0795c9
@ -1,11 +1,11 @@
|
||||
before_script:
|
||||
# Install dependencies
|
||||
- bash test/docker_install.sh > /dev/null
|
||||
- npm install
|
||||
- yarn
|
||||
|
||||
services:
|
||||
- mysql:latest
|
||||
- postgres:latest
|
||||
- mariadb:latest
|
||||
- postgres: alpine
|
||||
|
||||
variables:
|
||||
MYSQL_ROOT_PASSWORD: foo-bar-baz
|
||||
@ -23,9 +23,9 @@ cache:
|
||||
- node_modules/
|
||||
|
||||
test:6:
|
||||
image: node:6
|
||||
image: node:6-alpine
|
||||
script: npm run test
|
||||
|
||||
test:latest:
|
||||
image: node:latest
|
||||
image: node:alpine
|
||||
script: npm run test
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const helpers = require('./helpers');
|
||||
const Helpers = require('./Helpers');
|
||||
|
||||
/**
|
||||
* Base Database Driver
|
||||
@ -21,7 +21,7 @@ const Driver = {
|
||||
* @private
|
||||
*/
|
||||
_quote (str) {
|
||||
return (helpers.isString(str) &&
|
||||
return (Helpers.isString(str) &&
|
||||
!(str.startsWith(Driver.identifierStartChar) || str.endsWith(Driver.identifierEndChar))
|
||||
)
|
||||
? `${Driver.identifierStartChar}${str}${Driver.identifierEndChar}`
|
||||
@ -39,7 +39,7 @@ const Driver = {
|
||||
limit (sql, limit, offset) {
|
||||
sql += ` LIMIT ${limit}`;
|
||||
|
||||
if (helpers.isNumber(offset)) {
|
||||
if (Helpers.isNumber(offset)) {
|
||||
sql += ` OFFSET ${offset}`;
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ const Driver = {
|
||||
|
||||
// Handle commas
|
||||
if (str.includes(',')) {
|
||||
let parts = str.split(',').map(helpers.stringTrim);
|
||||
let parts = str.split(',').map(Helpers.stringTrim);
|
||||
str = parts.map(Driver.quoteIdentifiers).join(',');
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const helpers = require('./helpers');
|
||||
const Helpers = require('./Helpers');
|
||||
const QueryParser = require('./QueryParser');
|
||||
const State = require('./State');
|
||||
|
||||
@ -34,7 +34,7 @@ class QueryBuilderBase {
|
||||
['queryMap', 'groupString', 'orderString', 'havingMap'].forEach(clause => {
|
||||
let param = this.state[clause];
|
||||
|
||||
if (!helpers.isScalar(param)) {
|
||||
if (!Helpers.isScalar(param)) {
|
||||
Object.keys(param).forEach(part => {
|
||||
sql += param[part].conjunction + param[part].string;
|
||||
});
|
||||
@ -44,7 +44,7 @@ class QueryBuilderBase {
|
||||
});
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
@ -132,10 +132,10 @@ class QueryBuilderBase {
|
||||
_mixedSet (letName, valType, key, val) {
|
||||
let obj = {};
|
||||
|
||||
if (helpers.isScalar(key) && !helpers.isUndefined(val)) {
|
||||
if (Helpers.isScalar(key) && !Helpers.isUndefined(val)) {
|
||||
// Convert key/val pair to a simple object
|
||||
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
|
||||
obj[key] = key;
|
||||
} else {
|
||||
@ -165,9 +165,9 @@ class QueryBuilderBase {
|
||||
|
||||
_fixConjunction (conj) {
|
||||
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 ';
|
||||
} else if (lastItem.type === 'groupStart') {
|
||||
conj = '';
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const XRegExp = require('xregexp');
|
||||
const helpers = require('./helpers');
|
||||
const Helpers = require('./Helpers');
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
@ -59,7 +59,7 @@ class QueryParser {
|
||||
let output = [];
|
||||
|
||||
// Return non-array matches
|
||||
if (helpers.isNull(array)) {
|
||||
if (Helpers.isNull(array)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ class QueryParser {
|
||||
|
||||
// Quote the identifiers
|
||||
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);
|
||||
}
|
||||
});
|
||||
@ -166,9 +166,9 @@ class QueryParser {
|
||||
if (whereValues.indexOf(whereMap[key]) !== -1) {
|
||||
let value = whereMap[key];
|
||||
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 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;
|
||||
|
||||
// Remove the identifier in question,
|
||||
@ -210,7 +210,7 @@ class QueryParser {
|
||||
}, this);
|
||||
|
||||
// Quote identifiers
|
||||
if (helpers.isArray(parts.identifiers)) {
|
||||
if (Helpers.isArray(parts.identifiers)) {
|
||||
parts.identifiers.forEach(ident => {
|
||||
let index = parts.combined.indexOf(ident);
|
||||
if (index !== -1) {
|
||||
@ -224,7 +224,7 @@ class QueryParser {
|
||||
// This should only apply to literal values that are not
|
||||
// explicitly mapped to values, but have to be parsed from
|
||||
// a where condition,
|
||||
if (helpers.isArray(parts.literals)) {
|
||||
if (Helpers.isArray(parts.literals)) {
|
||||
parts.literals.forEach(lit => {
|
||||
let litIndex = parts.combined.indexOf(lit);
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const helpers = require('./helpers');
|
||||
const Helpers = require('./Helpers');
|
||||
|
||||
/**
|
||||
* Query result object
|
||||
@ -25,7 +25,7 @@ class Result {
|
||||
if (
|
||||
this._columns.length === 0 &&
|
||||
this._rows.length > 0 &&
|
||||
helpers.isObject(rows[0])
|
||||
Helpers.isObject(rows[0])
|
||||
) {
|
||||
this.columns = Object.keys(rows[0]);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
let helpers = require('../helpers');
|
||||
let Helpers = require('../Helpers');
|
||||
|
||||
/**
|
||||
* Driver for Firebird databases
|
||||
@ -24,7 +24,7 @@ module.exports = (() => {
|
||||
driver.limit = (origSql, limit, offset) => {
|
||||
let sql = `FIRST ${limit}`;
|
||||
|
||||
if (helpers.isNumber(offset)) {
|
||||
if (Helpers.isNumber(offset)) {
|
||||
sql += ` SKIP ${offset}`;
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
module.exports = (() => {
|
||||
delete require.cache[require.resolve('../Driver')];
|
||||
const driver = require('../Driver');
|
||||
const helpers = require('../helpers');
|
||||
const Helpers = require('../Helpers');
|
||||
|
||||
driver.identifierStartChar = '[';
|
||||
driver.identifierEndChar = ']';
|
||||
|
@ -8,7 +8,7 @@
|
||||
module.exports = (() => {
|
||||
delete require.cache[require.resolve('../Driver')];
|
||||
const driver = require('../Driver');
|
||||
const helpers = require('../helpers');
|
||||
const Helpers = require('../Helpers');
|
||||
|
||||
driver.identifierStartChar = '`';
|
||||
driver.identifierEndChar = '`';
|
||||
@ -22,7 +22,7 @@ module.exports = (() => {
|
||||
* @return {String} - Modified SQL statement
|
||||
*/
|
||||
driver.limit = (sql, limit, offset) => {
|
||||
sql += (helpers.isNumber(offset))
|
||||
sql += (Helpers.isNumber(offset))
|
||||
? ` LIMIT ${offset},${limit}`
|
||||
: ` LIMIT ${limit}`;
|
||||
|
||||
|
16
package.json
16
package.json
@ -37,15 +37,9 @@
|
||||
},
|
||||
"main": "lib/NodeQuery.js",
|
||||
"dependencies": {
|
||||
"dblite": "~0.7.6",
|
||||
"getargs": "~0.0.8",
|
||||
"glob": "^7.0.3",
|
||||
"mysql2": "^1.0.0-rc.1",
|
||||
"node-firebird": "^0.7.5",
|
||||
"pg": "^6.0.0",
|
||||
"require-reload": "~0.2.2",
|
||||
"sqlite3": "^3.1.8",
|
||||
"tedious": "^1.14.0",
|
||||
"xregexp": "^3.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -57,7 +51,7 @@
|
||||
"happiness": "^7.1.2",
|
||||
"jest": "^19.0.2",
|
||||
"jsdoc": "^3.4.3",
|
||||
"npm-run-all": "^3.0.0",
|
||||
"npm-run-all": "^4.0.2",
|
||||
"nsp": "^2.2.1"
|
||||
},
|
||||
"license": "MIT",
|
||||
@ -89,5 +83,13 @@
|
||||
"lint:src": "eslint ./lib",
|
||||
"lint:tests": "eslint ./test",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
const expect = require('chai').expect;
|
||||
|
||||
// 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 P = require('../lib/QueryParser');
|
||||
@ -17,10 +17,10 @@ let state = new State();
|
||||
let mixedSet = function mixedSet (letName, valType, key, val) {
|
||||
let obj = {};
|
||||
|
||||
if (helpers.isScalar(key) && !helpers.isUndefined(val)) {
|
||||
if (Helpers.isScalar(key) && !Helpers.isUndefined(val)) {
|
||||
// Convert key/val pair to a simple object
|
||||
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
|
||||
obj[key] = key;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user