sequelize/sequelize

View on GitHub
src/dialects/mssql/query.js

Summary

Maintainability
F
6 days
Test Coverage

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

  formatResults(data, rowCount) {
    if (this.isInsertQuery(data)) {
      this.handleInsertQuery(data);
      return [this.instance || data, rowCount];
    }
Severity: Minor
Found in src/dialects/mssql/query.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 _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

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

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

    Function handleInsertQuery has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      handleInsertQuery(results, metaData) {
        if (this.instance) {
          // add the inserted row id to the instance
          const autoIncrementAttribute = this.model.autoIncrementAttribute;
          let id = null;
    Severity: Minor
    Found in src/dialects/mssql/query.js - About 3 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 formatError has 69 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      formatError(err) {
        let match;
    
        match = err.message.match(
          /Violation of (?:UNIQUE|PRIMARY) KEY constraint '([^']*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/
    Severity: Major
    Found in src/dialects/mssql/query.js - About 2 hrs to fix

      Function formatResults has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        formatResults(data, rowCount) {
          if (this.isInsertQuery(data)) {
            this.handleInsertQuery(data);
            return [this.instance || data, rowCount];
          }
      Severity: Major
      Found in src/dialects/mssql/query.js - About 2 hrs to fix

        Function formatError has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          formatError(err) {
            let match;
        
            match = err.message.match(
              /Violation of (?:UNIQUE|PRIMARY) KEY constraint '([^']*)'. Cannot insert duplicate key in object '.*'.(:? The duplicate key value is \((.*)\).)?/
        Severity: Minor
        Found in src/dialects/mssql/query.js - About 2 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 _run has 60 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

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

          Consider simplifying this complex logical expression.
          Open

              if (this.instance) {
                // add the inserted row id to the instance
                const autoIncrementAttribute = this.model.autoIncrementAttribute;
                let id = null;
                let autoIncrementAttributeAlias = null;
          Severity: Critical
          Found in src/dialects/mssql/query.js - About 2 hrs to fix

            Function getSQLTypeFromJsType has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

              getSQLTypeFromJsType(value, TYPES) {
                const paramType = { type: TYPES.VarChar, typeOptions: {} };
                paramType.type = TYPES.NVarChar;
                if (typeof value === 'number') {
                  if (Number.isInteger(value)) {
            Severity: Minor
            Found in src/dialects/mssql/query.js - About 1 hr 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 query has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                const query = new Promise((resolve, reject) => {
                  // TRANSACTION SUPPORT
                  if (sql.startsWith('BEGIN TRANSACTION')) {
                    return connection.beginTransaction(
                      error => (error ? reject(error) : resolve([])),
            Severity: Minor
            Found in src/dialects/mssql/query.js - About 1 hr to fix

              Function handleShowIndexesQuery has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                handleShowIndexesQuery(data) {
                  // Group by index name, and collect all fields
                  data = data.reduce((acc, item) => {
                    if (!(item.index_name in acc)) {
                      acc[item.index_name] = item;
              Severity: Minor
              Found in src/dialects/mssql/query.js - About 1 hr to fix

                Function handleInsertQuery has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  handleInsertQuery(results, metaData) {
                    if (this.instance) {
                      // add the inserted row id to the instance
                      const autoIncrementAttribute = this.model.autoIncrementAttribute;
                      let id = null;
                Severity: Minor
                Found in src/dialects/mssql/query.js - About 1 hr to fix

                  Avoid too many return statements within this function.
                  Open

                        return data[0];
                  Severity: Major
                  Found in src/dialects/mssql/query.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return data;
                    Severity: Major
                    Found in src/dialects/mssql/query.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                            return [data, rowCount];
                      Severity: Major
                      Found in src/dialects/mssql/query.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return rowCount;
                        Severity: Major
                        Found in src/dialects/mssql/query.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                return data[0] ? data[0].AFFECTEDROWS : 0;
                          Severity: Major
                          Found in src/dialects/mssql/query.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return this.handleSelectQuery(data);
                            Severity: Major
                            Found in src/dialects/mssql/query.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return this.handleShowConstraintsQuery(data);
                              Severity: Major
                              Found in src/dialects/mssql/query.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      return data[0].version;
                                Severity: Major
                                Found in src/dialects/mssql/query.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        return [this.instance || data, data[0].$action === 'INSERT'];
                                  Severity: Major
                                  Found in src/dialects/mssql/query.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                          return [this.instance || data, rowCount];
                                    Severity: Major
                                    Found in src/dialects/mssql/query.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                            return this.handleShowIndexesQuery(data);
                                      Severity: Major
                                      Found in src/dialects/mssql/query.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                            return data;
                                        Severity: Major
                                        Found in src/dialects/mssql/query.js - About 30 mins to fix

                                          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

                                          Identical blocks of code found in 4 locations. Consider refactoring.
                                          Open

                                                _.forOwn(fields, (value, field) => {
                                                  errors.push(
                                                    new sequelizeErrors.ValidationErrorItem(
                                                      this.getUniqueConstraintErrorMessage(field),
                                                      'unique violation', // sequelizeErrors.ValidationErrorItem.Origins.DB,
                                          Severity: Major
                                          Found in src/dialects/mssql/query.js and 3 other locations - About 1 hr to fix
                                          src/dialects/mariadb/query.js on lines 237..248
                                          src/dialects/mysql/query.js on lines 214..225
                                          src/dialects/postgres/query.js on lines 339..350

                                          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 57.

                                          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 (sql.startsWith('ROLLBACK TRANSACTION')) {
                                                  return connection.rollbackTransaction(error => (error ? reject(error) : resolve([])), options.transaction.name);
                                                }
                                          Severity: Minor
                                          Found in src/dialects/mssql/query.js and 1 other location - About 55 mins to fix
                                          src/dialects/mssql/query.js on lines 66..68

                                          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 54.

                                          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 (sql.startsWith('SAVE TRANSACTION')) {
                                                  return connection.saveTransaction(error => (error ? reject(error) : resolve([])), options.transaction.name);
                                                }
                                          Severity: Minor
                                          Found in src/dialects/mssql/query.js and 1 other location - About 55 mins to fix
                                          src/dialects/mssql/query.js on lines 63..65

                                          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 54.

                                          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

                                          There are no issues that match your filters.

                                          Category
                                          Status