<commit_before>'use strict';

var Support   = require(__dirname + '/../support')
  , DataTypes = require(__dirname + '/../../../lib/data-types')
  , util      = require('util')
  , expectsql = Support.expectsql
  , current   = Support.sequelize
  , sql       = current.dialect.QueryGenerator;

// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation

suite(Support.getTestDialectTeaser('SQL'), function() {
  suite('whereQuery', function () {
    var testsql = function (params, options, expectation) {
      if (expectation === undefined) {
        expectation = options;
        options = undefined;
      }

      test(util.inspect(params, {depth: 10})+(options && ', '+util.inspect(options) || ''), function () {
        return expectsql(sql.whereQuery(params, options), expectation);
      });
    };

    testsql({}, {
      default: ''
    });
    testsql([], {
      default: ''
    });
    testsql({id: 1}, {
      default: 'WHERE [id] = 1'
    });
    testsql({id: 1}, {prefix: 'User'}, {
      default: 'WHERE [User].[id] = 1'
    });

    test("{ id: 1 }, { prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'})) }", function () {
      expectsql(sql.whereQuery({id: 1}, {prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'}))}), {
        default: 'WHERE [yolo.User].[id] = 1',
        postgres: 'WHERE "yolo"."User"."id" = 1',
        mssql: 'WHERE [yolo].[User].[id] = 1',
      });
    });

    testsql({
      name: 'a project',
      $or: [
        { id: [1,2,3] },
        { id: { $gt: 10 } }
      ]
    }, {
      default: "WHERE [name] = 'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)"
    });

    testsql({
      name: 'a project',
      id: {
        $or: [
          [1,2,3],
          { $gt: 10 }
        ]
      }
    }, {
      default: "WHERE [name] = 'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)"
    });
  });

  suite('whereItemQuery', function () {
    var testsql = function (key, value, options, expectation) {
      if (expectation === undefined) {
        expectation = options;
        options = undefined;
      }

      test(key+": "+util.inspect(value, {depth: 10})+(options && ', '+util.inspect(options) || ''), function () {
        return expectsql(sql.whereItemQuery(key, value, options), expectation);
      });
    };

    testsql(undefined, 'lol=1', {
      default: "lol=1"
    });

    testsql('deleted', null, {
      default: "`deleted` IS NULL",
      postgres: '"deleted" IS NULL',
      mssql: '[deleted] IS NULL'
    });

    suite('$in', function () {
      testsql('equipment', {
        $in: [1, 3]
      }, {
        default: '[equipment] IN (1, 3)'
      });

      testsql('equipment', {
        $in: []
      }, {
        default: '[equipment] IN (NULL)'
      });

      testsql('muscles', {
        in: [2, 4]
      }, {
        default: '[muscles] IN (2, 4)'
      });

      testsql('equipment', {
        $in: current.literal('(1, 2)')
      }, {
        default: '[equipment] IN (1, 2)'
      });
    });

    suite('Buffer', function () {
      testsql('field', new Buffer('Sequelize'), {
        postgres: '"field" = E\'\\\\x53657175656c697a65\'',
        sqlite: "`field` = X'53657175656c697a65'",
        mysql: "`field` = X'53657175656c697a65'",
        mssql: "[field] = 0x53657175656c697a65"
      });
    });

    suite('$not', function () {
      testsql('deleted', {
        $not: true
      }, {
        default: "[deleted] IS NOT true",
        mssql: "[deleted] IS NOT 'true'",
        sqlite: "`deleted` IS NOT 1"
      });

      testsql('deleted', {
        $not: null
      }, {
        default: "[deleted] IS NOT NULL"
      });

      testsql('muscles', {
        $not: 3
      }, {
        default: '[muscles] != 3'
      });
    });

    suite('$notIn', function () {
      testsql('equipment', {
        $notIn: []
      }, {
        default: '[equipment] NOT IN (NULL)'
      });

      testsql('equipment', {
        $notIn: [4, 19]
      }, {
        default: '[equipment] NOT IN (4, 19)'
      });

      testsql('equipment', {
        $notIn: current.literal('(1, 2)')
      }, {
        default: '[equipment] NOT IN (1, 2)'
      });
    });

    suite('$ne', function () {
      testsql('email', {
        $ne: '<EMAIL>'
      }, {
        default: "[email] != '<EMAIL>'"
      });
    });

    suite('$and/$or', function () {
      suite('$or', function () {
        testsql('email', {
          $or: ['<EMAIL>', '<EMAIL>']
        }, {
          default: '([email] = \'<EMAIL>\' OR [email] = \'<EMAIL>\')'
        });

        testsql('$or', [
          {email: '<EMAIL>'},
          {email: '<EMAIL>'}
        ], {
          default: '([email] = \'<EMAIL>\' OR [email] = \'<EMAIL>\')'<commit_msg>Test a more accurate use case.<commit_after>'use strict';

var Support   = require(__dirname + '/../support')
  , DataTypes = require(__dirname + '/../../../lib/data-types')
  , util      = require('util')
  , expectsql = Support.expectsql
  , current   = Support.sequelize
  , sql       = current.dialect.QueryGenerator;

// Notice: [] will be replaced by dialect specific tick/quote character when there is not dialect specific expectation but only a default expectation

suite(Support.getTestDialectTeaser('SQL'), function() {
  suite('whereQuery', function () {
    var testsql = function (params, options, expectation) {
      if (expectation === undefined) {
        expectation = options;
        options = undefined;
      }

      test(util.inspect(params, {depth: 10})+(options && ', '+util.inspect(options) || ''), function () {
        return expectsql(sql.whereQuery(params, options), expectation);
      });
    };

    testsql({}, {
      default: ''
    });
    testsql([], {
      default: ''
    });
    testsql({id: 1}, {
      default: 'WHERE [id] = 1'
    });
    testsql({id: 1}, {prefix: 'User'}, {
      default: 'WHERE [User].[id] = 1'
    });

    test("{ id: 1 }, { prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'})) }", function () {
      expectsql(sql.whereQuery({id: 1}, {prefix: current.literal(sql.quoteTable.call(current.dialect.QueryGenerator, {schema: 'yolo', tableName: 'User'}))}), {
        default: 'WHERE [yolo.User].[id] = 1',
        postgres: 'WHERE "yolo"."User"."id" = 1',
        mssql: 'WHERE [yolo].[User].[id] = 1',
      });
    });

    testsql({
      name: 'a project',
      $or: [
        { id: [1,2,3] },
        { id: { $gt: 10 } }
      ]
    }, {
      default: "WHERE [name] = 'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)"
    });

    testsql({
      name: 'a project',
      id: {
        $or: [
          [1,2,3],
          { $gt: 10 }
        ]
      }
    }, {
      default: "WHERE [name] = 'a project' AND ([id] IN (1, 2, 3) OR [id] > 10)"
    });
  });

  suite('whereItemQuery', function () {
    var testsql = function (key, value, options, expectation) {
      if (expectation === undefined) {
        expectation = options;
        options = undefined;
      }

      test(key+": "+util.inspect(value, {depth: 10})+(options && ', '+util.inspect(options) || ''), function () {
        return expectsql(sql.whereItemQuery(key, value, options), expectation);
      });
    };

    testsql(undefined, 'lol=1', {
      default: "lol=1"
    });

    testsql('deleted', null, {
      default: "`deleted` IS NULL",
      postgres: '"deleted" IS NULL',
      mssql: '[deleted] IS NULL'
    });

    suite('$in', function () {
      testsql('equipment', {
        $in: [1, 3]
      }, {
        default: '[equipment] IN (1, 3)'
      });

      testsql('equipment', {
        $in: []
      }, {
        default: '[equipment] IN (NULL)'
      });

      testsql('muscles', {
        in: [2, 4]
      }, {
        default: '[muscles] IN (2, 4)'
      });

      testsql('equipment', {
        $in: current.literal(
          '(select order_id from product_orders where product_id = 3)'
        )
      }, {
        default: '[equipment] IN (select order_id from product_orders where product_id = 3)'
      });
    });

    suite('Buffer', function () {
      testsql('field', new Buffer('Sequelize'), {
        postgres: '"field" = E\'\\\\x53657175656c697a65\'',
        sqlite: "`field` = X'53657175656c697a65'",
        mysql: "`field` = X'53657175656c697a65'",
        mssql: "[field] = 0x53657175656c697a65"
      });
    });

    suite('$not', function () {
      testsql('deleted', {
        $not: true
      }, {
        default: "[deleted] IS NOT true",
        mssql: "[deleted] IS NOT 'true'",
        sqlite: "`deleted` IS NOT 1"
      });

      testsql('deleted', {
        $not: null
      }, {
        default: "[deleted] IS NOT NULL"
      });

      testsql('muscles', {
        $not: 3
      }, {
        default: '[muscles] != 3'
      });
    });

    suite('$notIn', function () {
      testsql('equipment', {
        $notIn: []
      }, {
        default: '[equipment] NOT IN (NULL)'
      });

      testsql('equipment', {
        $notIn: [4, 19]
      }, {
        default: '[equipment] NOT IN (4, 19)'
      });

      testsql('equipment', {
        $notIn: current.literal(
          '(select order_id from product_orders where product_id = 3)'
        )
      }, {
        default: '[equipment] NOT IN (select order_id from product_orders where product_id = 3)'
      });
    });

    suite('$ne', function () {
      testsql('email', {
        $ne: '<EMAIL>'
      }, {
        default: "[email] != '<EMAIL>'"
      });
    });

    suite('$and/$or', function () {
      suite('$or', function () {
        testsql('email', {
          $or: ['<EMAIL>', '<EMAIL>']
        }, {
          default: '([email] = \'<EMAIL>\' OR [email] = \'<EMAIL>\')'
        });

        testsql('$or', [
          {email: '<EMAIL>'},
          {email: '<EMAIL>'}
        ], {
          default: '([email] = \'<EMAIL>\' OR [email] = \'<EMAIL>\')'
{'fraction_non_alphanumeric': 0.19877191244924236, 'fraction_numerical': 0.02436367237793404, 'mean_word_length': 2.0702341137123748, 'pattern_counts': {'":': 2, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7362739', 'n_tokens_mistral': 3566, 'n_tokens_neox': 3305, 'n_words': 730}