123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- var Test = require('../../support/test-runner');
- describe('Query Generation ::', function() {
- describe('WHERE NOT IN statements', function() {
- it('should generate a query', function(done) {
- Test({
- query: {
- select: ['name'],
- from: 'users',
- where: {
- and: [
- {
- id: {
- nin: [1, 2, 3]
- }
- }
- ]
- }
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select "name" from "users" where "id" not in ($1, $2, $3)',
- bindings: ['1', '2', '3']
- },
- {
- dialect: 'mysql',
- sql: 'select `name` from `users` where `id` not in (?, ?, ?)',
- bindings: ['1', '2', '3']
- },
- {
- dialect: 'sqlite3',
- sql: 'select "name" from "users" where "id" not in (?, ?, ?)',
- bindings: ['1', '2', '3']
- },
- {
- dialect: 'oracle',
- sql: 'select "name" from "users" where "id" not in (:1, :2, :3)',
- bindings: ['1', '2', '3']
- },
- {
- dialect: 'mariadb',
- sql: 'select `name` from `users` where `id` not in (?, ?, ?)',
- bindings: ['1', '2', '3']
- }
- ]
- }, done);
- });
- it('should generate a query when inside an OR statement', function(done) {
- Test({
- query: {
- select: ['name'],
- from: 'users',
- where: {
- or: [
- {
- id: {
- nin: [1, 2, 3]
- }
- },
- {
- id: {
- nin: [4, 5, 6]
- }
- }
- ]
- }
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select "name" from "users" where "id" not in ($1, $2, $3) or "id" not in ($4, $5, $6)',
- bindings: ['1', '2', '3', '4', '5', '6']
- },
- {
- dialect: 'mysql',
- sql: 'select `name` from `users` where `id` not in (?, ?, ?) or `id` not in (?, ?, ?)',
- bindings: ['1', '2', '3', '4', '5', '6']
- },
- {
- dialect: 'sqlite3',
- sql: 'select "name" from "users" where "id" not in (?, ?, ?) or "id" not in (?, ?, ?)',
- bindings: ['1', '2', '3', '4', '5', '6']
- },
- {
- dialect: 'oracle',
- sql: 'select "name" from "users" where "id" not in (:1, :2, :3) or "id" not in (:4, :5, :6)',
- bindings: ['1', '2', '3', '4', '5', '6']
- },
- {
- dialect: 'mariadb',
- sql: 'select `name` from `users` where `id` not in (?, ?, ?) or `id` not in (?, ?, ?)',
- bindings: ['1', '2', '3', '4', '5', '6']
- }
- ]
- }, done);
- });
- it('should generate a query when inside an OR statement with multiple criteria', function(done) {
- Test({
- query: {
- select: ['name'],
- from: 'users',
- where: {
- or: [
- {
- id: {
- nin: [1, 2, 3]
- },
- age: 21
- },
- {
- id: {
- nin: [4, 5, 6]
- }
- }
- ]
- }
- },
- outcomes: [
- {
- dialect: 'postgresql',
- sql: 'select "name" from "users" where ("id" not in ($1, $2, $3) and "age" = $4) or "id" not in ($5, $6, $7)',
- bindings: ['1', '2', '3', '21', '4', '5', '6']
- },
- {
- dialect: 'mysql',
- sql: 'select `name` from `users` where (`id` not in (?, ?, ?) and `age` = ?) or `id` not in (?, ?, ?)',
- bindings: ['1', '2', '3', '21', '4', '5', '6']
- },
- {
- dialect: 'sqlite3',
- sql: 'select "name" from "users" where ("id" not in (?, ?, ?) and "age" = ?) or "id" not in (?, ?, ?)',
- bindings: ['1', '2', '3', '21', '4', '5', '6']
- },
- {
- dialect: 'oracle',
- sql: 'select "name" from "users" where ("id" not in (:1, :2, :3) and "age" = :4) or "id" not in (:5, :6, :7)',
- bindings: ['1', '2', '3', '21', '4', '5', '6']
- },
- {
- dialect: 'mariadb',
- sql: 'select `name` from `users` where (`id` not in (?, ?, ?) and `age` = ?) or `id` not in (?, ?, ?)',
- bindings: ['1', '2', '3', '21', '4', '5', '6']
- }
- ]
- }, done);
- });
- });
- });
|