sequelize/sequelize

View on GitHub

Showing 787 of 787 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

      if (this.instance.dataValues) {
        for (const key in results[0]) {
          if (Object.prototype.hasOwnProperty.call(results[0], key)) {
            const record = results[0][key];

Severity: Major
Found in src/dialects/mssql/query.js and 1 other location - About 5 hrs to fix
src/dialects/postgres/query.js on lines 278..291

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 143.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function query has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  async query(sql, options) {
    options = { ...this.options.query, ...options };

    if (options.instance && !options.model) {
      options.model = options.instance.constructor;
Severity: Minor
Found in src/sequelize.js - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function _conformInclude has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
Open

  static _conformInclude(include, self) {
    if (include) {
      let model;

      if (include._pseudo) return include;
Severity: Minor
Found in src/model.js - About 5 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function constructor has 131 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  constructor(source, target, options) {
    super(source, target, options);

    if (this.options.through === undefined || this.options.through === true || this.options.through === null) {
      throw new AssociationError(
Severity: Major
Found in src/associations/belongs-to-many.js - About 5 hrs to fix

    Function _handleQueryResponse has 129 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _handleQueryResponse(metaData, columnTypes, err, results) {
        if (err) {
          err.sql = this.sql;
          throw this.formatError(err);
        }
    Severity: Major
    Found in src/dialects/sqlite/query.js - About 5 hrs to fix

      Function insertQuery has 126 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        insertQuery(table, valueHash, modelAttributes, options) {
          options = options || {};
          _.defaults(options, this.options);
      
          const modelAttributeMap = {};
      Severity: Major
      Found in src/dialects/abstract/query-generator.js - About 5 hrs to fix

        Function init has 126 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          static init(attributes, options = {}) {
            if (!options.sequelize) {
              throw new Error('No Sequelize instance passed');
            }
        
        
        Severity: Major
        Found in src/model.js - About 5 hrs to fix

          Function formatResults has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
          Open

            formatResults(data) {
              let result = this.instance;
          
              if (this.isBulkUpdateQuery() || this.isBulkDeleteQuery()) {
                return data.affectedRows;
          Severity: Minor
          Found in src/dialects/mariadb/query.js - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function _whereParseSingleValueObject has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
          Open

            _whereParseSingleValueObject(key, field, prop, value, options) {
              if (prop === Op.not) {
                if (Array.isArray(value)) {
                  prop = Op.notIn;
                } else if (value !== null && value !== true && value !== false) {
          Severity: Minor
          Found in src/dialects/abstract/query-generator.js - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function createTableQuery has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
          Open

            createTableQuery(tableName, attributes, options) {
              options = options || {};
          
              const primaryKeys = [];
              const needsMultiplePrimaryKeys =
          Severity: Minor
          Found in src/dialects/sqlite/query-generator.js - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                      if (itemHash === topHash) {
                        if (!resultMap[itemHash]) {
                          resultMap[itemHash] = values;
                        } else {
                          topExists = true;
          Severity: Major
          Found in src/dialects/abstract/query.js and 1 other location - About 4 hrs to fix
          src/dialects/abstract/query.js on lines 706..726

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 133.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  if (itemHash === topHash) {
                    if (!resultMap[itemHash]) {
                      resultMap[itemHash] = values;
                    } else {
                      topExists = true;
          Severity: Major
          Found in src/dialects/abstract/query.js and 1 other location - About 4 hrs to fix
          src/dialects/abstract/query.js on lines 621..641

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 133.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Function formatResults has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
          Open

            formatResults(data) {
              let result = this.instance;
          
              if (this.isInsertQuery(data)) {
                this.handleInsertQuery(data);
          Severity: Minor
          Found in src/dialects/mysql/query.js - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function generateThroughJoin has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
          Open

            generateThroughJoin(include, includeAs, parentTableName, topLevelInfo) {
              const through = include.through;
              const throughTable = through.model.getTableName();
              const throughAs = `${includeAs.internalAs}->${through.as}`;
              const externalThroughAs = `${includeAs.externalAs}.${through.as}`;
          Severity: Minor
          Found in src/dialects/abstract/query-generator.js - About 4 hrs to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function quote has 117 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            quote(collection, parent, connector) {
              // init
              const validOrderOptions = [
                'ASC',
                'DESC',
          Severity: Major
          Found in src/dialects/abstract/query-generator.js - About 4 hrs to fix

            Sequelize has 36 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class Sequelize {
              /**
               * Instantiate sequelize with name of database, username and password.
               *
               * @example
            Severity: Minor
            Found in src/sequelize.js - About 4 hrs to fix

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                function removeUnsupportedIntegerOptions(dataType) {
                  if (dataType._length || dataType.options.length || dataType._unsigned || dataType._zerofill) {
                    warn(
                      `PostgresSQL does not support '${dataType.key}' with LENGTH, UNSIGNED or ZEROFILL. Plain '${dataType.key}' will be used instead.`
                    );
              Severity: Major
              Found in src/dialects/postgres/data-types.js and 1 other location - About 4 hrs to fix
              src/dialects/mssql/data-types.js on lines 15..23

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 128.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Similar blocks of code found in 2 locations. Consider refactoring.
              Open

                function removeUnsupportedIntegerOptions(dataType) {
                  if (dataType._length || dataType.options.length || dataType._unsigned || dataType._zerofill) {
                    warn(`MSSQL does not support '${dataType.key}' with options. Plain '${dataType.key}' will be used instead.`);
                    dataType._length = undefined;
                    dataType.options.length = undefined;
              Severity: Major
              Found in src/dialects/mssql/data-types.js and 1 other location - About 4 hrs to fix
              src/dialects/postgres/data-types.js on lines 13..23

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 128.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              File query.js has 358 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              const AbstractQuery = require('../abstract/query');
              const QueryTypes = require('../../query-types');
              const sequelizeErrors = require('../../errors');
              const _ = require('lodash');
              const { logger } = require('../../utils/logger');
              Severity: Minor
              Found in src/dialects/postgres/query.js - About 4 hrs to fix

                Function _run has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
                Open

                  async _run(connection, sql, parameters) {
                    this.sql = sql;
                    const { options } = this;
                
                    const complete = this._logQuery(sql, debug, parameters);
                Severity: Minor
                Found in src/dialects/mssql/query.js - About 4 hrs to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Severity
                Category
                Status
                Source
                Language