Socket
Socket
Sign inDemoInstall

mysql-simple-query

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-simple-query - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

5

package.json
{
"name": "mysql-simple-query",
"version": "1.0.2",
"version": "1.0.3",
"description": "Simple query wrapper for mysql-promise to make querying, inserting, updating, and deleting easier for developers.",

@@ -36,4 +36,3 @@ "main": "mysqlSimpleQuery.js",

},
"dependencies": {
}
"dependencies": {}
}

@@ -10,2 +10,4 @@ const dbQuery = require('./util/dbQuery');

this.whereStatement = {};
this.whereLikeStatement = {};
this.whereLikeCondition = null;
this.groupByStatement = '';

@@ -41,2 +43,10 @@ this.orderByStatement = '';

whereLike(key, value, condition) {
this.whereLikeStatement[key] = value;
if (condition) {
this.whereLikeCondition = condition;
}
}
parseWhere() {

@@ -50,2 +60,10 @@ if(!isEmpty(this.whereStatement)) {

parseWhereLike() {
if(!isEmpty(this.whereLikeStatement)) {
return dbQuery.parseWhereLike(this.whereLikeStatement, this.whereLikeCondition);
}
return '';
}
groupBy(key) {

@@ -93,2 +111,6 @@ if(key)

if(this.parseWhereLike() !== '') {
queryStatement += ` ${this.parseWhereLike()}`;
}
if(this.groupByStatement !== '') {

@@ -95,0 +117,0 @@ queryStatement += ` ${this.groupByStatement}`;

@@ -58,2 +58,17 @@ const select = (select) => {

const parseWhereLike = (whereObject, orStatement = false) => {
let whereStatement = [];
for (let key of Object.keys(whereObject)) {
const value = whereObject[key];
whereStatement.push(`${key} LIKE "${value}"`);
}
if (orStatement) {
return `WHERE ${whereStatement.join(' OR ')}`;
}
return `WHERE ${whereStatement.join(' AND ')}`;
};
const groupBy = (key) => {

@@ -102,2 +117,3 @@ if(key)

parseWhere,
parseWhereLike,
groupBy,

@@ -104,0 +120,0 @@ orderBy,

@@ -20,2 +20,53 @@ const expect = require('chai').expect;

it('query with like statement', () => {
const test = new mysqlSimpleQuery();
test.select('*');
test.from('table');
test.join('table', 'table_1 = table_2');
test.whereLike('key', 'value');
test.groupBy('key');
test.orderBy('key');
const testResults = test.query();
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;');
});
it('where like with wildcard', () => {
const test = new mysqlSimpleQuery();
test.select('*');
test.from('table');
test.whereLike('key', '%value%');
const testResults = test.query();
expect(testResults).to.equal('SELECT * FROM table WHERE key LIKE "%value%";');
});
it('where like with multiple statements AND', () => {
const test = new mysqlSimpleQuery();
test.select('*');
test.from('table');
test.whereLike('key', '%value%');
test.whereLike('key2', '%value2%');
const testResults = test.query();
expect(testResults).to.equal('SELECT * FROM table WHERE key LIKE "%value%" AND key2 LIKE "%value2%";');
});
it('where like with multiple statements OR', () => {
const test = new mysqlSimpleQuery();
test.select('*');
test.from('table');
test.whereLike('key', '%value%', 'OR');
test.whereLike('key2', '%value2%');
const testResults = test.query();
expect(testResults).to.equal('SELECT * FROM table WHERE key LIKE "%value%" OR key2 LIKE "%value2%";');
});
it('insert', () => {

@@ -22,0 +73,0 @@ const test = new mysqlSimpleQuery();

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc