|
@ -1,11 +1,16 @@ |
|
|
/* global describe, it */ |
|
|
/* global describe, it */ |
|
|
var assert = require('assert'); |
|
|
var assert = require('assert'); |
|
|
var knex = require('knex')({client: 'pg' }); |
|
|
|
|
|
|
|
|
var Knex = require('knex'); |
|
|
var knexJsonQuery = require('./'); |
|
|
var knexJsonQuery = require('./'); |
|
|
require('simple-mocha'); |
|
|
require('simple-mocha'); |
|
|
|
|
|
|
|
|
|
|
|
var testData = { |
|
|
|
|
|
mysql:{}, |
|
|
|
|
|
pg:{}, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
var conditions= [ |
|
|
|
|
|
|
|
|
testData.pg.knex = Knex({client: 'pg' }); |
|
|
|
|
|
testData.pg.conditions = [ |
|
|
/* -----------Tests for and conditions---------- */ |
|
|
/* -----------Tests for and conditions---------- */ |
|
|
{ |
|
|
{ |
|
|
name: 'handle simple and conditions', |
|
|
name: 'handle simple and conditions', |
|
@ -157,6 +162,22 @@ var conditions= [ |
|
|
]; |
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testData.mysql.knex = Knex({client: 'mysql' }); |
|
|
|
|
|
testData.mysql.conditions = [ |
|
|
|
|
|
/* -----------Tests for and conditions---------- */ |
|
|
|
|
|
{ |
|
|
|
|
|
name: 'handle "and" condition with raw statement', |
|
|
|
|
|
input: { f1: { $raw: '< `use_limit`' }, f2: 20 }, |
|
|
|
|
|
output: 'select * where (`f1` < `use_limit` and `f2` = 20)' |
|
|
|
|
|
}, |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys( testData ).forEach(function(driver){ |
|
|
|
|
|
var data = testData[driver]; |
|
|
|
|
|
var conditions = data.conditions; |
|
|
|
|
|
var knex = data.knex; |
|
|
|
|
|
|
|
|
describe('SQL query generation from json query', function(){ |
|
|
describe('SQL query generation from json query', function(){ |
|
|
conditions.forEach(function(v){ |
|
|
conditions.forEach(function(v){ |
|
|
it( 'should ' + v.name , function(){ |
|
|
it( 'should ' + v.name , function(){ |
|
@ -166,3 +187,5 @@ describe('SQL query generation from json query', function(){ |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|