mysql-simple-query
Advanced tools
Comparing version 1.0.15 to 1.0.16
@@ -9,2 +9,3 @@ const dbQuery = require('./util/dbQuery'); | ||
this.whereStatement = {}; | ||
this.whereInStatement = {}; | ||
this.whereConditionUsed = false; | ||
@@ -59,2 +60,6 @@ this.whereLikeStatement = {}; | ||
whereIn(key, array) { | ||
this.whereInStatement[key] = array; | ||
} | ||
whereBetween(key, array) { | ||
@@ -80,2 +85,10 @@ this.whereBetweenStatement[key] = array; | ||
parseWhereIn() { | ||
if (!isEmpty(this.whereInStatement)) { | ||
return dbQuery.parseWhereIn(this.whereInStatement, this.whereConditionUsed); | ||
} | ||
return ''; | ||
} | ||
parseWhereBetween() { | ||
@@ -135,2 +148,6 @@ if (!isEmpty(this.whereBetweenStatement)) { | ||
if (this.parseWhereIn() !== '') { | ||
queryStatement += ` ${this.parseWhereIn()}`; | ||
} | ||
if (this.parseWhereLike() !== '') { | ||
@@ -137,0 +154,0 @@ queryStatement += ` ${this.parseWhereLike()}`; |
@@ -57,2 +57,13 @@ const select = select => { | ||
const parseWhereIn = (whereObject, where = false) => { | ||
let whereStatement = []; | ||
for (let key of Object.keys(whereObject)) { | ||
const value = whereObject[key]; | ||
whereStatement.push(`${key} IN (${value.join(',')})`); | ||
} | ||
return `${where ? 'AND' : 'WHERE'} ${whereStatement.join(' AND ')}`; | ||
}; | ||
const parseWhereLike = (whereObject, orStatement = false, where = false) => { | ||
@@ -132,2 +143,3 @@ let whereStatement = []; | ||
parseWhere, | ||
parseWhereIn, | ||
parseWhereLike, | ||
@@ -134,0 +146,0 @@ parseWhereBetween, |
{ | ||
"name": "mysql-simple-query", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"description": "Simple query wrapper for mysql-promise to make querying, inserting, updating, and deleting easier for developers.", | ||
@@ -5,0 +5,0 @@ "main": "mysqlSimpleQuery.js", |
@@ -10,2 +10,3 @@ const dbQuery = require('./util/dbQuery'); | ||
this.whereStatement = {}; | ||
this.whereInStatement = {}; | ||
this.whereConditionUsed = false; | ||
@@ -60,2 +61,6 @@ this.whereLikeStatement = {}; | ||
whereIn(key, array) { | ||
this.whereInStatement[key] = array; | ||
} | ||
whereBetween(key, array) { | ||
@@ -81,2 +86,10 @@ this.whereBetweenStatement[key] = array; | ||
parseWhereIn() { | ||
if(!isEmpty(this.whereInStatement)) { | ||
return dbQuery.parseWhereIn(this.whereInStatement, this.whereConditionUsed); | ||
} | ||
return ''; | ||
} | ||
parseWhereBetween() { | ||
@@ -138,2 +151,6 @@ if(!isEmpty(this.whereBetweenStatement)) { | ||
if(this.parseWhereIn() !== '') { | ||
queryStatement += ` ${this.parseWhereIn()}`; | ||
} | ||
if(this.parseWhereLike() !== '') { | ||
@@ -140,0 +157,0 @@ queryStatement += ` ${this.parseWhereLike()}`; |
@@ -62,2 +62,13 @@ const select = (select) => { | ||
const parseWhereIn = (whereObject, where = false) => { | ||
let whereStatement = []; | ||
for (let key of Object.keys(whereObject)) { | ||
const value = whereObject[key]; | ||
whereStatement.push(`${key} IN (${value.join(',')})`); | ||
} | ||
return `${(where ? 'AND' : 'WHERE')} ${whereStatement.join(' AND ')}`; | ||
}; | ||
const parseWhereLike = (whereObject, orStatement = false, where = false) => { | ||
@@ -141,2 +152,3 @@ let whereStatement = []; | ||
parseWhere, | ||
parseWhereIn, | ||
parseWhereLike, | ||
@@ -143,0 +155,0 @@ parseWhereBetween, |
@@ -171,2 +171,14 @@ const expect = require('chai').expect; | ||
}); | ||
it('query with where in clause', () => { | ||
const test = new mysqlSimpleQuery(); | ||
test.select('*'); | ||
test.from('table'); | ||
test.where('key', '%value%'); | ||
test.whereIn('column', [1, 2]); | ||
const testResults = test.query(); | ||
expect(testResults).to.equal('SELECT * FROM table WHERE key="%value%" AND column IN (1,2);'); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31992
821