diff --git a/README.md b/README.md index dcbb790905..a89e474e58 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,7 @@ gt - '>' - (colName,gt,colValue) gte - '>=' - (colName,gte,colValue) lt - '<' - (colName,lt,colValue) lte - '<=' - (colName,lte,colValue) +is - 'is' - (colName,is,true/false/null) in - 'in' - (colName,in,val1,val2,val3,val4) like - 'like' - (colName,like,~name) note: use ~ in place of % nlike - 'not like' - (colName,nlike,~name) note: use ~ in place of % diff --git a/lib/util/cmd.helper.js b/lib/util/cmd.helper.js index 7084c17ccb..8b50e47dc2 100644 --- a/lib/util/cmd.helper.js +++ b/lib/util/cmd.helper.js @@ -11,7 +11,7 @@ program.on('--help', () => { }) program - .version('0.2.9') + .version('0.3.0') .option('-h, --host ', 'hostname / localhost by default') .option('-u, --user ', 'username of database / root by default') .option('-p, --password ', 'password of database / empty by default') diff --git a/lib/util/whereClause.helper.js b/lib/util/whereClause.helper.js index 8f42af0dc7..6570342487 100644 --- a/lib/util/whereClause.helper.js +++ b/lib/util/whereClause.helper.js @@ -44,6 +44,22 @@ function prepareLikeValue(value) { } +function prepareIsValue(value) { + + //return value.replace("~", "%"); + if(value === 'null'){ + return null; + } else if (value === 'true'){ + return true; + } else if (value === 'false'){ + return false; + } else { + return null + } + +} + + function replaceWhereParamsToQMarks(openParentheses, str, comparisonOperator) { @@ -103,13 +119,13 @@ function getComparisonOperator(operator) { return '>=' break; - // case 'is': - // return ' is ' - // break; + case 'is': + return ' is ' + break; - // case 'isnot': - // return ' is not ' - // break; + case 'isnot': + return ' is not ' + break; // case 'isnull': // return ' is NULL ' @@ -253,6 +269,8 @@ exports.getConditionClause = function (whereInQueryParams, condType = 'where') { whereParams = whereParams.concat(obj.whereParams) } else if (comparisonOperator === ' like ' || comparisonOperator === ' not like ') { whereParams.push(prepareLikeValue(variableValue[1])) + } else if (comparisonOperator === ' is ') { + whereParams.push(prepareIsValue(variableValue[1])) } else { whereParams.push(variableValue[1]) } diff --git a/package.json b/package.json index adee76481b..b1ccabf657 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xmysql", - "version": "0.2.9", + "version": "0.3.0", "description": "One command to generate REST APIs for any MySql database", "main": "index.js", "scripts": { diff --git a/tests/tests.js b/tests/tests.js index 1cc2ab5442..d8b4eeb74e 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -783,7 +783,24 @@ describe('xmysql : tests', function () { }); }); - http://localhost:3000/api/offices?_where=(city,like,~on~) + it('GET /api/productlines?_where=(htmlDescription,is,null) should PASS', function (done) { + + //post to an url with data + agent.get('/api/productlines?_where=(htmlDescription,is,null)') //enter url + .expect(200)//200 for success 4xx for failure + .end(function (err, res) { + // Handle /api/v error + if (err) { + return done(err); + } + + //validate response + res.body.length.should.be.equals(6) + + return done(); + + }); + }); it('GET /api/offices?_where=(city,like,~on~) should PASS', function (done) { @@ -1801,6 +1818,21 @@ describe('xmysql : tests', function () { }); + it('where clause unit ?_where=(a,is,null)~and(b,is,true)~and(c,is,false) should PASS', function (done) { + + var err = whereClause.getConditionClause('(a,is,null)~and(b,is,true)~and(c,is,false)') + + //console.log(err.params[1],err); + + err.err.should.be.equal(0) + err.query.should.be.equal('(?? is ?)and(?? is ?)and(?? is ?)') + //err.params[1].should.be.equal(null) + err.params[3].should.be.equal(true) + err.params[5].should.be.equal(false) + + done() + + }); // it('GET http://localhost:3000/api/customers/groupby?_fields=city,country&_having=(customerNumber,lt,110) should PASS', function (done) { //