mysql-simple-query
Advanced tools
Comparing version 1.0.6 to 1.0.7
@@ -9,2 +9,3 @@ const dbQuery = require('./util/dbQuery'); | ||
this.whereStatement = {}; | ||
this.whereConditionUsed = false; | ||
this.whereLikeStatement = {}; | ||
@@ -15,2 +16,3 @@ this.whereLikeCondition = null; | ||
this.limitStatement = ''; | ||
this.offsetStatement = ''; | ||
this.table = null; | ||
@@ -41,2 +43,3 @@ } | ||
this.whereStatement[key] = value; | ||
this.whereConditionUsed = true; | ||
} | ||
@@ -62,3 +65,3 @@ | ||
if (!isEmpty(this.whereLikeStatement)) { | ||
return dbQuery.parseWhereLike(this.whereLikeStatement, this.whereLikeCondition, this.whereStatement); | ||
return dbQuery.parseWhereLike(this.whereLikeStatement, this.whereLikeCondition, this.whereConditionUsed); | ||
} | ||
@@ -87,2 +90,8 @@ | ||
offset(number) { | ||
if (number) { | ||
this.offsetStatement = dbQuery.offset(number); | ||
} | ||
} | ||
queryRaw(query) { | ||
@@ -126,2 +135,6 @@ return query.trim(); | ||
if (this.offsetStatement !== '') { | ||
queryStatement += ` ${this.offsetStatement}`; | ||
} | ||
queryStatement += ';'; | ||
@@ -128,0 +141,0 @@ |
@@ -92,2 +92,10 @@ const select = select => { | ||
const offset = number => { | ||
if (number) { | ||
return `OFFSET ${number}`; | ||
} | ||
throw new Error('Number is required for limit'); | ||
}; | ||
const update = data => { | ||
@@ -113,3 +121,4 @@ let updateData = []; | ||
limit, | ||
update | ||
update, | ||
offset | ||
}; |
{ | ||
"name": "mysql-simple-query", | ||
"version": "1.0.6", | ||
"version": "1.0.7", | ||
"description": "Simple query wrapper for mysql-promise to make querying, inserting, updating, and deleting easier for developers.", | ||
@@ -5,0 +5,0 @@ "main": "mysqlSimpleQuery.js", |
@@ -16,2 +16,3 @@ const dbQuery = require('./util/dbQuery'); | ||
this.limitStatement = ''; | ||
this.offsetStatement = ''; | ||
this.table = null; | ||
@@ -89,2 +90,8 @@ } | ||
offset(number) { | ||
if(number) { | ||
this.offsetStatement = dbQuery.offset(number); | ||
} | ||
} | ||
queryRaw(query) { | ||
@@ -128,2 +135,6 @@ return query.trim(); | ||
if(this.offsetStatement !== '') { | ||
queryStatement += ` ${this.offsetStatement}`; | ||
} | ||
queryStatement += ';'; | ||
@@ -130,0 +141,0 @@ |
@@ -100,2 +100,11 @@ const select = (select) => { | ||
const offset = (number) => { | ||
if(number) | ||
{ | ||
return `OFFSET ${number}`; | ||
} | ||
throw new Error('Number is required for limit'); | ||
}; | ||
const update = (data) => { | ||
@@ -121,3 +130,4 @@ let updateData = []; | ||
limit, | ||
update | ||
update, | ||
offset | ||
}; |
@@ -31,4 +31,2 @@ const expect = require('chai').expect; | ||
console.log(testResults); | ||
expect(testResults).to.equal('SELECT * FROM table INNER JOIN table ON table_1 = table_2 WHERE key LIKE "value" GROUP BY key ORDER BY key ASC;'); | ||
@@ -84,2 +82,25 @@ }); | ||
it('Query with limit', () => { | ||
const test = new mysqlSimpleQuery(); | ||
test.select('*'); | ||
test.from('table'); | ||
test.limit(100); | ||
const testResults = test.query(); | ||
expect(testResults).to.equal('SELECT * FROM table LIMIT 100;'); | ||
}); | ||
it('Query with limit with offset', () => { | ||
const test = new mysqlSimpleQuery(); | ||
test.select('*'); | ||
test.from('table'); | ||
test.limit(100); | ||
test.offset(200); | ||
const testResults = test.query(); | ||
expect(testResults).to.equal('SELECT * FROM table LIMIT 100 OFFSET 200;'); | ||
}); | ||
it('insert', () => { | ||
@@ -127,5 +148,4 @@ const test = new mysqlSimpleQuery(); | ||
const results = test.delete('product_option_set'); | ||
console.log(results); | ||
expect(results).to.equal('DELETE FROM product_option_set WHERE product_id="2222"'); | ||
}); | ||
}); |
27200
693