2014-09-01 17:18:45 +02:00
|
|
|
/*global describe, it*/
|
|
|
|
|
|
|
|
'use strict';
|
2013-09-12 01:00:44 -04:00
|
|
|
|
|
|
|
module.exports = function(knex) {
|
|
|
|
describe('unions', function() {
|
2018-08-03 15:11:38 -04:00
|
|
|
it('handles unions with a callback', function() {
|
2013-09-12 01:00:44 -04:00
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union(function() {
|
2018-07-09 08:10:34 -04:00
|
|
|
this.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 2);
|
2013-09-12 01:00:44 -04:00
|
|
|
});
|
|
|
|
});
|
2018-08-03 15:11:38 -04:00
|
|
|
|
|
|
|
it('handles unions with an array of callbacks', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union([
|
|
|
|
function() {
|
|
|
|
this.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 2);
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
this.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 3);
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles unions with a list of callbacks', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union(
|
|
|
|
function() {
|
|
|
|
this.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 2);
|
|
|
|
},
|
|
|
|
function() {
|
|
|
|
this.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 3);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles unions with an array of builders', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union([
|
|
|
|
knex
|
|
|
|
.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 2),
|
|
|
|
knex
|
|
|
|
.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 3),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles unions with a list of builders', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union(
|
|
|
|
knex
|
|
|
|
.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 2),
|
|
|
|
knex
|
|
|
|
.select('*')
|
|
|
|
.from('accounts')
|
|
|
|
.where('id', 3)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles unions with a raw query', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
2018-11-23 19:58:23 +08:00
|
|
|
.union(
|
|
|
|
knex.raw('select * from ?? where ?? = ?', ['accounts', 'id', 2])
|
|
|
|
);
|
2018-08-03 15:11:38 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('handles unions with an array raw queries', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union([
|
2018-11-23 19:58:23 +08:00
|
|
|
knex.raw('select * from ?? where ?? = ?', ['accounts', 'id', 2]),
|
|
|
|
knex.raw('select * from ?? where ?? = ?', ['accounts', 'id', 3]),
|
2018-08-03 15:11:38 -04:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('handles unions with a list of raw queries', function() {
|
|
|
|
return knex('accounts')
|
|
|
|
.select('*')
|
|
|
|
.where('id', '=', 1)
|
|
|
|
.union(
|
2018-11-23 19:58:23 +08:00
|
|
|
knex.raw('select * from ?? where ?? = ?', ['accounts', 'id', 2]),
|
|
|
|
knex.raw('select * from ?? where ?? = ?', ['accounts', 'id', 3])
|
2018-08-03 15:11:38 -04:00
|
|
|
);
|
|
|
|
});
|
2013-09-12 01:00:44 -04:00
|
|
|
});
|
2014-09-01 17:18:45 +02:00
|
|
|
};
|