sequelizer.unionAll.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var Sequelizer = require('../../../index')({ dialect: 'postgres' }).sequelizer;
  2. var analyze = require('../../support/analyze');
  3. var assert = require('assert');
  4. describe('Sequelizer ::', function() {
  5. describe('UNION ALL statements', function() {
  6. it('should generate a simple query with a UNION statement', function() {
  7. var tree = analyze({
  8. select: ['*'],
  9. from: 'users',
  10. where: {
  11. and: [
  12. {
  13. firstName: 'Bob'
  14. }
  15. ]
  16. },
  17. unionAll: [
  18. {
  19. select: ['*'],
  20. from: 'users',
  21. where: {
  22. and: [
  23. {
  24. lastName: 'Smith'
  25. }
  26. ]
  27. }
  28. },
  29. {
  30. select: ['*'],
  31. from: 'users',
  32. where: {
  33. and: [
  34. {
  35. middleName: 'Allen'
  36. }
  37. ]
  38. }
  39. }
  40. ]
  41. });
  42. var result = Sequelizer(tree);
  43. assert.equal(result.sql, 'select * from "users" where "firstName" = $1 union all (select * from "users" where "lastName" = $2) union all (select * from "users" where "middleName" = $3)');
  44. assert.deepEqual(result.bindings, ['Bob', 'Smith', 'Allen']);
  45. });
  46. });
  47. });