sequelizer.where.simple.test.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 Simple statements', function() {
  6. it('should generate a query with a simple WHERE statement', function() {
  7. var tree = analyze({
  8. select: ['id'],
  9. where: {
  10. and: [
  11. {
  12. firstName: 'Test'
  13. },
  14. {
  15. lastName: 'User'
  16. }
  17. ]
  18. },
  19. from: 'users'
  20. });
  21. var result = Sequelizer(tree);
  22. assert.equal(result.sql, 'select "id" from "users" where "firstName" = $1 and "lastName" = $2');
  23. assert.deepEqual(result.bindings, ['Test', 'User']);
  24. });
  25. it('should generate a valid query when operators are used', function() {
  26. var tree = analyze({
  27. select: ['*'],
  28. where: {
  29. and: [
  30. {
  31. votes: {
  32. '>': 100
  33. }
  34. }
  35. ]
  36. },
  37. from: 'users'
  38. });
  39. var result = Sequelizer(tree);
  40. assert.equal(result.sql, 'select * from "users" where "votes" > $1');
  41. assert.deepEqual(result.bindings, ['100']);
  42. });
  43. it('should generate a valid query when multiple columns and operators are used', function() {
  44. var tree = analyze({
  45. select: ['*'],
  46. where: {
  47. and: [
  48. {
  49. votes: {
  50. '>': 100
  51. }
  52. },
  53. {
  54. age: {
  55. '<': 50
  56. }
  57. }
  58. ]
  59. },
  60. from: 'users'
  61. });
  62. var result = Sequelizer(tree);
  63. assert.equal(result.sql, 'select * from "users" where "votes" > $1 and "age" < $2');
  64. assert.deepEqual(result.bindings, ['100', '50']);
  65. });
  66. });
  67. });