sequelize/sequelize

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

Summary

Maintainability
F
4 days
Test Coverage

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 formatError has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

  formatError(err) {
    const errCode = err.errno || err.code;

    switch (errCode) {
      case 1062: {
Severity: Minor
Found in src/dialects/mysql/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 formatResults has 73 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  formatResults(data) {
    let result = this.instance;

    if (this.isInsertQuery(data)) {
      this.handleInsertQuery(data);
Severity: Major
Found in src/dialects/mysql/query.js - About 2 hrs to fix

    Function formatError has 55 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      formatError(err) {
        const errCode = err.errno || err.code;
    
        switch (errCode) {
          case 1062: {
    Severity: Major
    Found in src/dialects/mysql/query.js - About 2 hrs to fix

      Function logWarnings has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        async logWarnings(results) {
          const warningResults = await this.run('SHOW WARNINGS');
          const warningMessage = `MySQL Warnings (${this.connection.uuid || 'default'}): `;
          const messages = [];
          for (const _warningRow of warningResults) {
      Severity: Minor
      Found in src/dialects/mysql/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 run has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        async run(sql, parameters) {
          this.sql = sql;
          const { connection, options } = this;
      
          //do we need benchmark for this query execution
      Severity: Minor
      Found in src/dialects/mysql/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 run has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async run(sql, parameters) {
          this.sql = sql;
          const { connection, options } = this;
      
          //do we need benchmark for this query execution
      Severity: Minor
      Found in src/dialects/mysql/query.js - About 1 hr to fix

        Avoid too many return statements within this function.
        Open

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

          Avoid too many return statements within this function.
          Open

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

            Avoid too many return statements within this function.
            Open

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

              Avoid too many return statements within this function.
              Open

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

                Avoid too many return statements within this function.
                Open

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

                  Avoid too many return statements within this function.
                  Open

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

                    Avoid too many return statements within this function.
                    Open

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

                      Avoid too many return statements within this function.
                      Open

                            return [result, data.affectedRows === 1];
                      Severity: Major
                      Found in src/dialects/mysql/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/mysql/query.js - About 30 mins to fix

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

                            static formatBindParameters(sql, values, dialect) {
                              const bindParam = [];
                              const replacementFunc = (match, key, values) => {
                                if (values[key] !== undefined) {
                                  bindParam.push(values[key]);
                          Severity: Major
                          Found in src/dialects/mysql/query.js and 1 other location - About 3 hrs to fix
                          src/dialects/mariadb/query.js on lines 18..29

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

                          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 2 locations. Consider refactoring.
                          Open

                                for (const _warningResult of _warningRow) {
                                  if (Object.prototype.hasOwnProperty.call(_warningResult, 'Message')) {
                                    messages.push(_warningResult.Message);
                                  } else {
                                    for (const _objectKey of _warningResult.keys()) {
                          Severity: Major
                          Found in src/dialects/mysql/query.js and 1 other location - About 3 hrs to fix
                          src/dialects/mariadb/query.js on lines 199..207

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

                          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 (
                                    data.constructor.name === 'ResultSetHeader' &&
                                    this.model &&
                                    this.model.autoIncrementAttribute &&
                                    this.model.autoIncrementAttribute === this.model.primaryKeyAttribute &&
                          Severity: Major
                          Found in src/dialects/mysql/query.js and 1 other location - About 2 hrs to fix
                          src/dialects/sqlite/query.js on lines 82..98

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

                          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

                                    for (let i = startId; i < startId + data.affectedRows; i++) {
                                      result.push({
                                        [this.model.rawAttributes[this.model.primaryKeyAttribute].field]: i
                                      });
                                    }
                          Severity: Major
                          Found in src/dialects/mysql/query.js and 1 other location - About 1 hr to fix
                          src/dialects/sqlite/query.js on lines 91..95

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

                          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/mysql/query.js and 3 other locations - About 1 hr to fix
                          src/dialects/mariadb/query.js on lines 237..248
                          src/dialects/mssql/query.js on lines 277..288
                          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

                          There are no issues that match your filters.

                          Category
                          Status