sequelizer.update.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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('UPDATE statements', function() {
  6. it('should generate a simple query with an UPDATE statement', function() {
  7. var tree = analyze({
  8. update: {
  9. status: 'archived'
  10. },
  11. where: {
  12. and: [
  13. {
  14. publishedDate: { '>': 2000 }
  15. }
  16. ]
  17. },
  18. using: 'books'
  19. });
  20. var result = Sequelizer(tree);
  21. assert.equal(result.sql, 'update "books" set "status" = $1 where "publishedDate" > $2');
  22. assert.deepEqual(result.bindings, ['archived', 2000]);
  23. });
  24. it('should generate a query with multiple values being inserted', function() {
  25. var tree = analyze({
  26. update: {
  27. status: 'archived',
  28. active: false
  29. },
  30. where: {
  31. and: [
  32. {
  33. publishedDate: {
  34. '>': 2000
  35. }
  36. }
  37. ]
  38. },
  39. using: 'books'
  40. });
  41. var result = Sequelizer(tree);
  42. assert.equal(result.sql, 'update "books" set "active" = $1, "status" = $2 where "publishedDate" > $3');
  43. assert.deepEqual(result.bindings, [false, 'archived', 2000]);
  44. });
  45. it('should generate a query with a NULL value for input', function() {
  46. var tree = analyze({
  47. update: {
  48. status: null
  49. },
  50. using: 'books'
  51. });
  52. var result = Sequelizer(tree);
  53. assert.equal(result.sql, 'update "books" set "status" = $1');
  54. assert.deepEqual(result.bindings, [null]);
  55. });
  56. });
  57. });