unionAll.test.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var Test = require('../../support/test-runner');
  2. describe('Query Generation ::', function() {
  3. describe('UNION ALL statements', function() {
  4. it('should generate a UNION ALL query', function(done) {
  5. Test({
  6. query: {
  7. select: ['*'],
  8. from: 'users',
  9. where: {
  10. and: [
  11. {
  12. firstName: 'Bob'
  13. }
  14. ]
  15. },
  16. unionAll: [
  17. {
  18. select: ['*'],
  19. from: 'users',
  20. where: {
  21. and: [
  22. {
  23. lastName: 'Smith'
  24. }
  25. ]
  26. }
  27. },
  28. {
  29. select: ['*'],
  30. from: 'users',
  31. where: {
  32. and: [
  33. {
  34. middleName: 'Allen'
  35. }
  36. ]
  37. }
  38. }
  39. ]
  40. },
  41. outcomes: [
  42. {
  43. dialect: 'postgresql',
  44. sql: 'select * from "users" where "firstName" = $1 union all (select * from "users" where "lastName" = $2) union all (select * from "users" where "middleName" = $3)',
  45. bindings: ['Bob', 'Smith', 'Allen']
  46. },
  47. {
  48. dialect: 'mysql',
  49. sql: 'select * from `users` where `firstName` = ? union all (select * from `users` where `lastName` = ?) union all (select * from `users` where `middleName` = ?)',
  50. bindings: ['Bob', 'Smith', 'Allen']
  51. },
  52. {
  53. dialect: 'sqlite3',
  54. sql: 'select * from "users" where "firstName" = ? union all (select * from "users" where "lastName" = ?) union all (select * from "users" where "middleName" = ?)',
  55. bindings: ['Bob', 'Smith', 'Allen']
  56. },
  57. {
  58. dialect: 'oracle',
  59. sql: 'select * from "users" where "firstName" = :1 union all (select * from "users" where "lastName" = :2) union all (select * from "users" where "middleName" = :3)',
  60. bindings: ['Bob', 'Smith', 'Allen']
  61. },
  62. {
  63. dialect: 'mariadb',
  64. sql: 'select * from `users` where `firstName` = ? union all (select * from `users` where `lastName` = ?) union all (select * from `users` where `middleName` = ?)',
  65. bindings: ['Bob', 'Smith', 'Allen']
  66. }
  67. ]
  68. }, done);
  69. });
  70. });
  71. });