{"size": 1742, "ext": "js", "max_stars_repo_path": "test/unit/sequelizer/sequelizer.update.test.js", "max_stars_repo_name": "gammeo/waterline-sql-builder", "max_stars_repo_stars_event_min_datetime": "2017-10-23T14:13:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-27T06:01:38.000Z", "max_issues_repo_path": "test/unit/sequelizer/sequelizer.update.test.js", "max_issues_repo_name": "gammeo/waterline-sql-builder", "max_issues_repo_issues_event_min_datetime": "2019-05-10T19:29:44.000Z", "max_issues_repo_issues_event_max_datetime": "2021-04-27T07:17:26.000Z", "max_forks_repo_path": "test/unit/sequelizer/sequelizer.update.test.js", "max_forks_repo_name": "gammeo/waterline-sql-builder", "max_forks_repo_forks_event_min_datetime": "2018-04-17T01:15:08.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-13T09:57:52.000Z"}
{"max_stars_count": 6, "max_issues_count": 2, "max_forks_count": 9, "avg_line_length": 27.21875, "max_line_length": 109, "alphanum_fraction": 0.5034443169}
var Sequelizer = require('../../../index')({ dialect: 'postgres' }).sequelizer;
var analyze = require('../../support/analyze');
var assert = require('assert');

describe('Sequelizer ::', function() {
  describe('UPDATE statements', function() {
    it('should generate a simple query with an UPDATE statement', function() {
      var tree = analyze({
        update: {
          status: 'archived'
        },
        where: {
          and: [
            {
              publishedDate: { '>': 2000 }
            }
          ]
        },
        using: 'books'
      });

      var result = Sequelizer(tree);
      assert.equal(result.sql, 'update "books" set "status" = $1 where "publishedDate" > $2');
      assert.deepEqual(result.bindings, ['archived', 2000]);
    });

    it('should generate a query with multiple values being inserted', function() {
      var tree = analyze({
        update: {
          status: 'archived',
          active: false
        },
        where: {
          and: [
            {
              publishedDate: {
                '>': 2000
              }
            }
          ]
        },
        using: 'books'
      });

      var result = Sequelizer(tree);
      assert.equal(result.sql, 'update "books" set "active" = $1, "status" = $2 where "publishedDate" > $3');
      assert.deepEqual(result.bindings, [false, 'archived', 2000]);
    });

    it('should generate a query with a NULL value for input', function() {
      var tree = analyze({
        update: {
          status: null
        },
        using: 'books'
      });

      var result = Sequelizer(tree);
      assert.equal(result.sql, 'update "books" set "status" = $1');
      assert.deepEqual(result.bindings, [null]);
    });
  });
});
