sequelize/sequelize

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

Summary

Maintainability
F
1 wk
Test Coverage

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

const _ = require('lodash');
const Utils = require('../../utils');
const AbstractQueryGenerator = require('../abstract/query-generator');
const util = require('util');
const Op = require('../../operators');
Severity: Minor
Found in src/dialects/mysql/query-generator.js - About 6 hrs to fix

    MySQLQueryGenerator has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class MySQLQueryGenerator extends AbstractQueryGenerator {
      constructor(options) {
        super(options);
    
        this.OperatorMap = {
    Severity: Minor
    Found in src/dialects/mysql/query-generator.js - About 3 hrs to fix

      Function handleSequelizeMethod has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        handleSequelizeMethod(smth, tableName, factory, options, prepend) {
          if (smth instanceof Utils.Json) {
            // Parse nested object
            if (smth.conditions) {
              const conditions = this.parseConditionObject(smth.conditions).map(
      Severity: Minor
      Found in src/dialects/mysql/query-generator.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 createTableQuery has 65 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        createTableQuery(tableName, attributes, options) {
          options = {
            engine: 'InnoDB',
            charset: null,
            rowFormat: null,
      Severity: Major
      Found in src/dialects/mysql/query-generator.js - About 2 hrs to fix

        Function attributeToSQL has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          attributeToSQL(attribute, options) {
            if (!_.isPlainObject(attribute)) {
              attribute = {
                type: attribute
              };
        Severity: Minor
        Found in src/dialects/mysql/query-generator.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 attributeToSQL has 57 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          attributeToSQL(attribute, options) {
            if (!_.isPlainObject(attribute)) {
              attribute = {
                type: attribute
              };
        Severity: Major
        Found in src/dialects/mysql/query-generator.js - About 2 hrs to fix

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

            createTableQuery(tableName, attributes, options) {
              options = {
                engine: 'InnoDB',
                charset: null,
                rowFormat: null,
          Severity: Minor
          Found in src/dialects/mysql/query-generator.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 _checkValidJsonStatement has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

            _checkValidJsonStatement(stmt) {
              if (typeof stmt !== 'string') {
                return false;
              }
          
          
          Severity: Minor
          Found in src/dialects/mysql/query-generator.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 _checkValidJsonStatement has 42 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            _checkValidJsonStatement(stmt) {
              if (typeof stmt !== 'string') {
                return false;
              }
          
          
          Severity: Minor
          Found in src/dialects/mysql/query-generator.js - About 1 hr to fix

            Function handleSequelizeMethod has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              handleSequelizeMethod(smth, tableName, factory, options, prepend) {
                if (smth instanceof Utils.Json) {
                  // Parse nested object
                  if (smth.conditions) {
                    const conditions = this.parseConditionObject(smth.conditions).map(
            Severity: Minor
            Found in src/dialects/mysql/query-generator.js - About 1 hr to fix

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

                    if (dataType.includes('PRIMARY KEY')) {
                      primaryKeys.push(attr);
              
                      if (dataType.includes('REFERENCES')) {
                        // MySQL doesn't support inline REFERENCES declarations: move to the end
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 1 day to fix
              src/dialects/mssql/query-generator.js on lines 142..160

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

              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 (smth instanceof Utils.Json) {
                    // Parse nested object
                    if (smth.conditions) {
                      const conditions = this.parseConditionObject(smth.conditions).map(
                        condition =>
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 1 day to fix
              src/dialects/postgres/query-generator.js on lines 220..249

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

              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

                  while (currentIndex < stmt.length) {
                    const string = stmt.substr(currentIndex);
                    const functionMatches = JSON_FUNCTION_REGEX.exec(string);
                    if (functionMatches) {
                      currentIndex += functionMatches[0].indexOf('(');
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 1 day to fix
              src/dialects/postgres/query-generator.js on lines 175..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 229.

              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

                createDatabaseQuery(databaseName, options) {
                  options = {
                    charset: null,
                    collate: null,
                    ...options
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 3 hrs to fix
              src/dialects/mariadb/query-generator.js on lines 5..19

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

              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

                    if (attribute.references.key) {
                      template += ` (${this.quoteIdentifier(attribute.references.key)})`;
                    } else {
                      template += ` (${this.quoteIdentifier('id')})`;
                    }
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 2 hrs to fix
              src/dialects/mssql/query-generator.js on lines 636..640

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

              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

                showTablesQuery(database) {
                  let query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'";
                  if (database) {
                    query += ` AND TABLE_SCHEMA = ${this.escape(database)}`;
                  } else {
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 1 hr to fix
              src/dialects/mariadb/query-generator.js on lines 40..48

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

              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

                describeTableQuery(tableName, schema, schemaDelimiter) {
                  const table = this.quoteTable(
                    this.addSchema({
                      tableName,
                      _schema: schema,
              Severity: Major
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 1 hr to fix
              src/dialects/abstract/query-generator.js on lines 67..77

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

              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

                        attributesClause += `, UNIQUE ${this.quoteIdentifier(indexName)} (${columns.fields
                          .map(field => this.quoteIdentifier(field))
                          .join(', ')})`;
              Severity: Minor
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 55 mins to fix
              src/dialects/mssql/query-generator.js on lines 173..175

              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

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

                        if (typeof indexName !== 'string') {
                          indexName = `uniq_${tableName}_${columns.fields.join('_')}`;
                        }
              Severity: Minor
              Found in src/dialects/mysql/query-generator.js and 1 other location - About 30 mins to fix
              src/dialects/mssql/query-generator.js on lines 169..171

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

              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