123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- var Test = require('../../support/test-runner');
- describe('Query Generation ::', function() {
- describe('Grouping statements with AND', function() {
- it('should generate a query when an AND statement is used as an array', function(done) {
- Test({
- query: {
- select: ['*'],
- from: 'users',
- where: {
- and: [
- {
- firstName: 'foo'
- },
- {
- lastName: 'bar'
- }
- ]
- }
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select * from "users" where "firstName" = $1 and "lastName" = $2',
- bindings: ['foo', 'bar']
- },
- {
- dialect: 'mysql',
- sql: 'select * from `users` where `firstName` = ? and `lastName` = ?',
- bindings: ['foo', 'bar']
- },
- {
- dialect: 'sqlite3',
- sql: 'select * from "users" where "firstName" = ? and "lastName" = ?',
- bindings: ['foo', 'bar']
- },
- {
- dialect: 'oracle',
- sql: 'select * from "users" where "firstName" = :1 and "lastName" = :2',
- bindings: ['foo', 'bar']
- },
- {
- dialect: 'mariadb',
- sql: 'select * from `users` where `firstName` = ? and `lastName` = ?',
- bindings: ['foo', 'bar']
- }
- ]
- }, done);
- });
- it('should generate a query when a nested OR statement is used', function(done) {
- Test({
- query: {
- select: ['*'],
- from: 'users',
- where: {
- and: [
- {
- or: [
- {
- firstName: 'John'
- },
- {
- lastName: 'Smith'
- }
- ]
- },
- {
- or: [
- {
- qty: {
- '>': 100
- }
- },
- {
- price: {
- '<': 10.01
- }
- }
- ]
- }
- ]
- }
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select * from "users" where ("firstName" = $1 or "lastName" = $2) and ("qty" > $3 or "price" < $4)',
- bindings: ['John', 'Smith', '100', '10.01']
- },
- {
- dialect: 'mysql',
- sql: 'select * from `users` where (`firstName` = ? or `lastName` = ?) and (`qty` > ? or `price` < ?)',
- bindings: ['John', 'Smith', '100', '10.01']
- },
- {
- dialect: 'sqlite3',
- sql: 'select * from "users" where ("firstName" = ? or "lastName" = ?) and ("qty" > ? or "price" < ?)',
- bindings: ['John', 'Smith', '100', '10.01']
- },
- {
- dialect: 'oracle',
- sql: 'select * from "users" where ("firstName" = :1 or "lastName" = :2) and ("qty" > :3 or "price" < :4)',
- bindings: ['John', 'Smith', '100', '10.01']
- },
- {
- dialect: 'mariadb',
- sql: 'select * from `users` where (`firstName` = ? or `lastName` = ?) and (`qty` > ? or `price` < ?)',
- bindings: ['John', 'Smith', '100', '10.01']
- }
- ]
- }, done);
- });
- });
- });
|