2014-10-23 10:53:16 -04:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-28 16:46:48 -04:00
|
|
|
var helpers = require('../lib/helpers');
|
|
|
|
|
|
|
|
module.exports = (function QueryBuilderTestBase() {
|
|
|
|
|
|
|
|
// That 'new' keyword is annoying
|
|
|
|
if ( ! (this instanceof QueryBuilderTestBase)) return new QueryBuilderTestBase();
|
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
var base = {};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inject the appropriate driver and adapter for the test suite
|
|
|
|
*
|
|
|
|
* @param {Object} qb - The adapter-specific query builder object
|
|
|
|
* @param {Function} callback - The test callback
|
|
|
|
* @return void
|
|
|
|
*/
|
2014-10-28 16:46:48 -04:00
|
|
|
this._setUp = function(qb, callback) {
|
2014-10-23 10:53:16 -04:00
|
|
|
base.qb = qb;
|
|
|
|
base.testCallback = callback;
|
2014-10-28 16:46:48 -04:00
|
|
|
|
|
|
|
this.qb = base.qb;
|
2014-10-23 10:53:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generic query builder tests
|
|
|
|
*/
|
2014-10-28 16:46:48 -04:00
|
|
|
this.tests = {
|
2014-10-24 14:26:31 -04:00
|
|
|
// ! Get tests
|
2014-10-23 10:53:16 -04:00
|
|
|
'Get tests' : {
|
2014-10-23 11:59:42 -04:00
|
|
|
'Get with function': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 11:59:42 -04:00
|
|
|
base.qb.select('id, COUNT(id) as count')
|
|
|
|
.from('create_test')
|
|
|
|
.groupBy('id')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-23 11:59:42 -04:00
|
|
|
},
|
2014-10-23 10:53:16 -04:00
|
|
|
'Basic select all get': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 15:46:54 -04:00
|
|
|
base.qb.get('create_test', base.testCallback.bind(this, test));
|
2014-10-23 10:53:16 -04:00
|
|
|
},
|
|
|
|
'Basic select all with from': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 10:53:16 -04:00
|
|
|
base.qb.from('create_test')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-23 13:50:11 -04:00
|
|
|
},
|
|
|
|
'Get with limit': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 15:46:54 -04:00
|
|
|
base.qb.get('create_test', 2, base.testCallback.bind(this, test));
|
2014-10-23 13:50:11 -04:00
|
|
|
},
|
|
|
|
'Get with limit and offset': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 15:46:54 -04:00
|
|
|
base.qb.get('create_test', 2, 1, base.testCallback.bind(this, test));
|
2014-10-23 15:33:20 -04:00
|
|
|
},
|
|
|
|
'Test get with having': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 15:33:20 -04:00
|
|
|
base.qb.select('id')
|
|
|
|
.from('create_test')
|
|
|
|
.groupBy('id')
|
|
|
|
.having({'id >':1})
|
|
|
|
.having('id !=', 3)
|
2014-10-28 16:46:48 -04:00
|
|
|
.having('id', 900)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-23 15:33:20 -04:00
|
|
|
},
|
|
|
|
"Test get with 'orHaving'": function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 15:33:20 -04:00
|
|
|
base.qb.select('id')
|
|
|
|
.from('create_test')
|
|
|
|
.groupBy('id')
|
|
|
|
.having({'id >':1})
|
|
|
|
.orHaving('id !=', 3)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-23 10:53:16 -04:00
|
|
|
}
|
|
|
|
},
|
2014-10-24 14:26:31 -04:00
|
|
|
// ! Select tests
|
2014-10-23 10:53:16 -04:00
|
|
|
'Select tests' : {
|
2014-10-23 15:33:20 -04:00
|
|
|
'Select where get': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 15:49:17 -04:00
|
|
|
base.qb.select(['id', 'key as k', 'val'])
|
|
|
|
.where('id >', 1)
|
|
|
|
.where('id <', 900)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get('create_test', 2, 1, base.testCallback.bind(this, test));
|
2014-10-24 14:26:31 -04:00
|
|
|
},
|
|
|
|
'Select where get 2': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 15:33:20 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.where('id !=', 1)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get('create_test', 2, 1, base.testCallback.bind(this, test));
|
2014-10-23 15:49:17 -04:00
|
|
|
},
|
|
|
|
'Multi Order By': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-23 15:49:17 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.orderBy('id, key')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Select get': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get('create_test', 2, 1, base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Select from get': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test ct')
|
|
|
|
.where('id >', 1)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Select from limit get': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test ct')
|
|
|
|
.where('id >', 1)
|
|
|
|
.limit(3)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-23 15:33:20 -04:00
|
|
|
}
|
2014-10-23 10:53:16 -04:00
|
|
|
},
|
2014-10-24 14:26:31 -04:00
|
|
|
// ! Grouping tests
|
2014-10-23 10:53:16 -04:00
|
|
|
'Grouping tests' : {
|
2014-10-24 10:30:54 -04:00
|
|
|
'Using grouping method': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.groupStart()
|
|
|
|
.where('id >', 1)
|
|
|
|
.where('id <', 900)
|
|
|
|
.groupEnd()
|
|
|
|
.limit(2, 1)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
2014-10-28 16:46:48 -04:00
|
|
|
'Using where first grouping': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.where('id !=', 5)
|
|
|
|
.groupStart()
|
|
|
|
.where('id >', 1)
|
|
|
|
.where('id <', 900)
|
|
|
|
.groupEnd()
|
|
|
|
.limit(2, 1)
|
|
|
|
.get(base.testCallback.bind(this, test));
|
|
|
|
},
|
2014-10-24 10:30:54 -04:00
|
|
|
'Using or grouping method': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.groupStart()
|
|
|
|
.where('id >', 1)
|
|
|
|
.where('id <', 900)
|
|
|
|
.groupEnd()
|
|
|
|
.orGroupStart()
|
|
|
|
.where('id', 0)
|
|
|
|
.groupEnd()
|
|
|
|
.limit(2, 1)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Using or not grouping method': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.groupStart()
|
|
|
|
.where('id >', 1)
|
|
|
|
.where('id <', 900)
|
|
|
|
.groupEnd()
|
|
|
|
.orNotGroupStart()
|
|
|
|
.where('id', 0)
|
|
|
|
.groupEnd()
|
|
|
|
.limit(2, 1)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
}
|
2014-10-23 10:53:16 -04:00
|
|
|
},
|
2014-10-24 14:26:31 -04:00
|
|
|
// ! Where in tests
|
2014-10-23 10:53:16 -04:00
|
|
|
'Where in tests' : {
|
2014-10-24 10:30:54 -04:00
|
|
|
'Where in': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.whereIn('id', [0, 6, 56, 563, 341])
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Or Where in': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.where('key', 'false')
|
|
|
|
.orWhereIn('id', [0, 6, 56, 563, 341])
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Where Not in': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.where('key', 'false')
|
|
|
|
.whereNotIn('id', [0, 6, 56, 563, 341])
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Or Where Not in': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.where('key', 'false')
|
|
|
|
.orWhereNotIn('id', [0, 6, 56, 563, 341])
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
}
|
2014-10-23 10:53:16 -04:00
|
|
|
},
|
2014-10-27 15:46:54 -04:00
|
|
|
// ! Query modifier tests
|
2014-10-23 10:53:16 -04:00
|
|
|
'Query modifier tests': {
|
2014-10-24 10:30:54 -04:00
|
|
|
'Order By': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.where('id >', 0)
|
|
|
|
.where('id <', 9000)
|
|
|
|
.orderBy('id', 'DESC')
|
|
|
|
.orderBy('k', "ASC")
|
|
|
|
.limit(5, 2)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Group by': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.where('id >', 0)
|
|
|
|
.where('id <', 9000)
|
2014-10-28 09:05:27 -04:00
|
|
|
.groupBy('k')
|
|
|
|
.groupBy(['id', 'val'])
|
2014-10-24 10:30:54 -04:00
|
|
|
.orderBy('id', 'DESC')
|
|
|
|
.orderBy('k', "ASC")
|
|
|
|
.limit(5, 2)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Or Where': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.select('id, key as k, val')
|
|
|
|
.from('create_test')
|
|
|
|
.where(' id ', 1)
|
|
|
|
.orWhere('key >', 0)
|
|
|
|
.limit(2, 1)
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Like' : function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.like('key', 'og')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 10:30:54 -04:00
|
|
|
},
|
|
|
|
'Or Like': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 10:30:54 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.like('key', 'og')
|
|
|
|
.orLike('key', 'val')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 14:26:31 -04:00
|
|
|
},
|
|
|
|
'Not Like': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 14:26:31 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.like('key', 'og', 'before')
|
|
|
|
.notLike('key', 'val')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 14:26:31 -04:00
|
|
|
},
|
|
|
|
'Or Not Like': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 14:26:31 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.like('key', 'og', 'before')
|
|
|
|
.orNotLike('key', 'val')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 14:26:31 -04:00
|
|
|
},
|
|
|
|
'Like Before': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 14:26:31 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.like('key', 'og', 'before')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-24 14:26:31 -04:00
|
|
|
},
|
|
|
|
'Like After': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 14:26:31 -04:00
|
|
|
base.qb.from('create_test')
|
|
|
|
.like('key', 'og', 'after')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-27 10:35:16 -04:00
|
|
|
},
|
2014-10-24 14:26:31 -04:00
|
|
|
'Basic Join': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-24 14:26:31 -04:00
|
|
|
base.qb.from('create_test ct')
|
2014-10-27 10:35:16 -04:00
|
|
|
.join('create_join cj', 'cj.id=ct.id')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-27 10:35:16 -04:00
|
|
|
},
|
|
|
|
'Left Join': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 10:35:16 -04:00
|
|
|
base.qb.from('create_test ct')
|
|
|
|
.join('create_join cj', 'cj.id=ct.id', 'left')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-27 10:35:16 -04:00
|
|
|
},
|
|
|
|
'InnerJoin': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 10:35:16 -04:00
|
|
|
base.qb.from('create_test ct')
|
|
|
|
.join('create_join cj', 'cj.id=ct.id', 'inner')
|
2014-10-27 15:46:54 -04:00
|
|
|
.get(base.testCallback.bind(this, test));
|
2014-10-27 10:35:16 -04:00
|
|
|
}
|
2014-10-23 10:53:16 -04:00
|
|
|
},
|
2014-10-27 15:46:54 -04:00
|
|
|
// ! DB Update test
|
2014-10-23 10:53:16 -04:00
|
|
|
'DB update tests' : {
|
2014-10-28 16:46:48 -04:00
|
|
|
setUp: function(callback) {
|
|
|
|
var sql = base.qb.driver.truncate('create_test');
|
|
|
|
base.qb.adapter.execute(sql, function(err, result) {
|
|
|
|
if (err) {
|
|
|
|
throw new Error(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
tearDown: function(callback) {
|
|
|
|
callback();
|
|
|
|
},
|
2014-10-27 13:36:10 -04:00
|
|
|
'Test Insert': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 10:35:16 -04:00
|
|
|
base.qb.set('id', 98)
|
|
|
|
.set('key', 84)
|
|
|
|
.set('val', 120)
|
2014-10-27 15:46:54 -04:00
|
|
|
.insert('create_test', base.testCallback.bind(this, test));
|
2014-10-27 10:35:16 -04:00
|
|
|
},
|
|
|
|
'Test Insert Object': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 10:35:16 -04:00
|
|
|
base.qb.insert('create_test', {
|
|
|
|
id: 587,
|
|
|
|
key: 1,
|
|
|
|
val: 2
|
2014-10-27 15:46:54 -04:00
|
|
|
}, base.testCallback.bind(this, test));
|
2014-10-27 13:36:10 -04:00
|
|
|
},
|
|
|
|
'Test Update': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 13:36:10 -04:00
|
|
|
base.qb.where('id', 7)
|
|
|
|
.update('create_test', {
|
|
|
|
id: 7,
|
|
|
|
key: 'gogle',
|
|
|
|
val: 'non-word'
|
2014-10-27 15:46:54 -04:00
|
|
|
}, base.testCallback.bind(this, test));
|
2014-10-27 13:36:10 -04:00
|
|
|
},
|
|
|
|
'Test set Array Update': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 13:36:10 -04:00
|
|
|
var object = {
|
|
|
|
id: 22,
|
|
|
|
key: 'gogle',
|
|
|
|
val: 'non-word'
|
|
|
|
};
|
2014-10-23 10:53:16 -04:00
|
|
|
|
2014-10-27 13:36:10 -04:00
|
|
|
base.qb.set(object)
|
|
|
|
.where('id', 22)
|
2014-10-27 15:46:54 -04:00
|
|
|
.update('create_test', base.testCallback.bind(this, test));
|
2014-10-27 13:36:10 -04:00
|
|
|
},
|
|
|
|
'Test where set update': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 13:36:10 -04:00
|
|
|
base.qb.where('id', 36)
|
|
|
|
.set('id', 36)
|
|
|
|
.set('key', 'gogle')
|
|
|
|
.set('val', 'non-word')
|
2014-10-27 15:46:54 -04:00
|
|
|
.update('create_test', base.testCallback.bind(this, test));
|
2014-10-27 13:36:10 -04:00
|
|
|
},
|
|
|
|
'Test delete': function(test) {
|
2014-10-28 16:46:48 -04:00
|
|
|
test.expect(1);
|
2014-10-27 15:46:54 -04:00
|
|
|
base.qb.delete('create_test', {id: 5}, base.testCallback.bind(this, test));
|
2014-10-28 16:46:48 -04:00
|
|
|
}/*,
|
|
|
|
'delete with where': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
base.qb.where('id', 5)
|
|
|
|
.delete('create_test', base.testCallback.bind(this, test));
|
|
|
|
}*/
|
|
|
|
},
|
|
|
|
// ! Get compiled tests
|
|
|
|
'Get compiled tests' : {
|
|
|
|
'select': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
var string = base.qb.select('id')
|
|
|
|
.from('create_test')
|
|
|
|
.getCompiledSelect(true);
|
|
|
|
|
|
|
|
test.equal(true, helpers.isString(string));
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
'select from': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
var string = base.qb.select('id')
|
|
|
|
.getCompiledSelect('create_test', true);
|
|
|
|
|
|
|
|
test.equal(true, helpers.isString(string));
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
'insert': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
|
|
|
|
var string = base.qb.set('id', 3)
|
|
|
|
.getCompiledInsert('create_test');
|
|
|
|
|
|
|
|
test.equal(true, helpers.isString(string));
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
'update': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
|
|
|
|
var string = base.qb.set('id', 3)
|
|
|
|
.where('id', 5)
|
|
|
|
.getCompiledUpdate('create_test');
|
|
|
|
|
|
|
|
test.equal(true, helpers.isString(string));
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
'delete': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
|
|
|
|
var string = base.qb.where('id', 5)
|
|
|
|
.getCompiledDelete('create_test');
|
|
|
|
|
|
|
|
test.equal(true, helpers.isString(string));
|
|
|
|
|
|
|
|
test.done();
|
2014-10-27 13:36:10 -04:00
|
|
|
}
|
2014-10-23 10:53:16 -04:00
|
|
|
},
|
2014-10-28 16:46:48 -04:00
|
|
|
// ! Misc tests
|
|
|
|
'Misc tests' : {
|
|
|
|
'Get State': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
|
|
|
|
base.qb.select('foo')
|
|
|
|
.from('bar')
|
|
|
|
.where('baz', 'foobar');
|
|
|
|
|
|
|
|
var state = {
|
|
|
|
// Arrays/Maps
|
|
|
|
queryMap: [],
|
|
|
|
values: [],
|
|
|
|
whereValues: [],
|
|
|
|
setArrayKeys: [],
|
|
|
|
orderArray: [],
|
|
|
|
groupArray: [],
|
|
|
|
havingMap: [],
|
|
|
|
whereMap: {},
|
2014-10-23 10:53:16 -04:00
|
|
|
|
2014-10-28 16:46:48 -04:00
|
|
|
// Partials
|
|
|
|
selectString: '',
|
|
|
|
fromString: '',
|
|
|
|
setString: '',
|
|
|
|
orderString: '',
|
|
|
|
groupString: '',
|
|
|
|
|
|
|
|
// Other various values
|
|
|
|
limit: null,
|
|
|
|
offset: null
|
|
|
|
};
|
|
|
|
|
|
|
|
test.notDeepEqual(JSON.stringify(state), JSON.stringify(base.qb.getState()));
|
|
|
|
test.done();
|
|
|
|
},
|
|
|
|
'Reset State': function(test) {
|
|
|
|
test.expect(1);
|
|
|
|
|
|
|
|
base.qb.select('foo')
|
|
|
|
.from('bar')
|
|
|
|
.where('baz', 'foobar');
|
|
|
|
|
|
|
|
base.qb.resetQuery();
|
|
|
|
|
|
|
|
var state = {
|
|
|
|
// Arrays/Maps
|
|
|
|
queryMap: [],
|
|
|
|
values: [],
|
|
|
|
whereValues: [],
|
|
|
|
setArrayKeys: [],
|
|
|
|
orderArray: [],
|
|
|
|
groupArray: [],
|
|
|
|
havingMap: [],
|
|
|
|
whereMap: {},
|
|
|
|
|
|
|
|
// Partials
|
|
|
|
selectString: '',
|
|
|
|
fromString: '',
|
|
|
|
setString: '',
|
|
|
|
orderString: '',
|
|
|
|
groupString: '',
|
|
|
|
|
|
|
|
// Other various values
|
|
|
|
limit: null,
|
|
|
|
offset: null
|
|
|
|
};
|
|
|
|
|
|
|
|
test.deepEqual(state, base.qb.getState());
|
|
|
|
|
|
|
|
test.done();
|
|
|
|
}
|
2014-10-23 10:53:16 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-28 16:46:48 -04:00
|
|
|
return this;
|
2014-10-23 10:53:16 -04:00
|
|
|
}());
|