sequelizer.where.in.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 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. in: [1, 2, 3]
  15. }
  16. }
  17. ]
  18. }
  19. });
  20. var result = Sequelizer(tree);
  21. assert.equal(result.sql, 'select "name" from "users" where "id" in ($1, $2, $3)');
  22. assert.deepEqual(result.bindings, ['1', '2', '3']);
  23. });
  24. it('should generate a query when in an OR statement', function() {
  25. var tree = analyze({
  26. select: ['name'],
  27. from: 'users',
  28. where: {
  29. or: [
  30. {
  31. id: {
  32. in: [1, 2, 3]
  33. }
  34. },
  35. {
  36. id: {
  37. in: [4, 5, 6]
  38. }
  39. }
  40. ]
  41. }
  42. });
  43. var result = Sequelizer(tree);
  44. assert.equal(result.sql, 'select "name" from "users" where "id" in ($1, $2, $3) or "id" in ($4, $5, $6)');
  45. assert.deepEqual(result.bindings, ['1', '2', '3', '4', '5', '6']);
  46. });
  47. });
  48. });