sequelizer.where.not.in.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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('WHERE NOT IN statements', function() {
  6. it('should generate a query', function() {
  7. var tree = analyze({
  8. select: ['name'],
  9. from: 'users',
  10. where: {
  11. and: [
  12. {
  13. id: {
  14. nin: [1, 2, 3]
  15. }
  16. }
  17. ]
  18. }
  19. });
  20. var result = Sequelizer(tree);
  21. assert.equal(result.sql, 'select "name" from "users" where "id" not in ($1, $2, $3)');
  22. assert.deepEqual(result.bindings, ['1', '2', '3']);
  23. });
  24. it('should generate a query when used in a conjunction', function() {
  25. var tree = analyze({
  26. select: ['name'],
  27. from: 'users',
  28. where: {
  29. and: [
  30. {
  31. id: {
  32. nin: [1, 2, 3]
  33. },
  34. age: {
  35. nin: [30, 40, 50]
  36. }
  37. }
  38. ]
  39. }
  40. });
  41. var result = Sequelizer(tree);
  42. assert.equal(result.sql, 'select "name" from "users" where ("id" not in ($1, $2, $3) and "age" not in ($4, $5, $6))');
  43. assert.deepEqual(result.bindings, ['1', '2', '3', '30', '40', '50']);
  44. });
  45. it('should generate a query when in an OR statement', function() {
  46. var tree = analyze({
  47. select: ['name'],
  48. from: 'users',
  49. where: {
  50. or: [
  51. {
  52. id: {
  53. nin: [1, 2, 3]
  54. }
  55. },
  56. {
  57. id: {
  58. nin: [4, 5, 6]
  59. }
  60. }
  61. ]
  62. }
  63. });
  64. var result = Sequelizer(tree);
  65. assert.equal(result.sql, 'select "name" from "users" where "id" not in ($1, $2, $3) or "id" not in ($4, $5, $6)');
  66. assert.deepEqual(result.bindings, ['1', '2', '3', '4', '5', '6']);
  67. });
  68. it('should generate a query when in an OR statement with multiple criteria', function() {
  69. var tree = analyze({
  70. select: ['name'],
  71. from: 'users',
  72. where: {
  73. or: [
  74. {
  75. and: [
  76. {
  77. id: {
  78. nin: [1, 2, 3]
  79. }
  80. },
  81. {
  82. age: 21
  83. }
  84. ]
  85. },
  86. {
  87. id: {
  88. nin: [4, 5, 6]
  89. }
  90. }
  91. ]
  92. }
  93. });
  94. var result = Sequelizer(tree);
  95. assert.equal(result.sql, 'select "name" from "users" where ("id" not in ($1, $2, $3) and "age" = $4) or "id" not in ($5, $6, $7)');
  96. assert.deepEqual(result.bindings, ['1', '2', '3', '21', '4', '5', '6']);
  97. });
  98. });
  99. });