sequelize/sequelize

View on GitHub

Showing 503 of 787 total issues

Function _sanitize has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  _sanitize(value) {
    if (value !== null && value !== undefined) {
      if (Buffer.isBuffer(value) && value.length === 1) {
        // Bit fields are returned as buffers
        value = value[0];
Severity: Minor
Found in src/data-types.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 add has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  async add(sourceInstance, newInstances, options) {
    // If newInstances is null or undefined, no-op
    if (!newInstances) return Promise.resolve();

    options = { ...options };
Severity: Minor
Found in src/associations/belongs-to-many.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 updateQuery has 76 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  updateQuery(tableName, attrValueHash, where, options, attributes) {
    options = options || {};
    _.defaults(options, this.options);

    attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, options.omitNull, options);
Severity: Major
Found in src/dialects/abstract/query-generator.js - About 3 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

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

      class AbstractQuery {
        constructor(connection, sequelize, options) {
          this.uuid = uuid();
          this.connection = connection;
          this.instance = options.instance;
      Severity: Minor
      Found in src/dialects/abstract/query.js - About 3 hrs to fix

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

        class SQLiteQueryGenerator extends MySqlQueryGenerator {
          createSchema() {
            return "SELECT name FROM `sqlite_master` WHERE type='table' and name!='sqlite_sequence';";
          }
        
        
        Severity: Minor
        Found in src/dialects/sqlite/query-generator.js - About 3 hrs to fix

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

              formatError(err) {
                let match;
                let table;
                let index;
                let fields;
            Severity: Minor
            Found in src/dialects/postgres/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 createTableQuery has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              createTableQuery(tableName, attributes, options) {
                const primaryKeys = [],
                  foreignKeys = {},
                  attributesClauseParts = [];
            
            
            Severity: Minor
            Found in src/dialects/mssql/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 getQueryOrders has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              getQueryOrders(options, model, subQuery) {
                const mainQueryOrder = [];
                const subQueryOrder = [];
            
                if (Array.isArray(options.order)) {
            Severity: Minor
            Found in src/dialects/abstract/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 getConstraintSnippet has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
            Open

              getConstraintSnippet(tableName, options) {
                let constraintSnippet, constraintName;
            
                const fieldsSql = options.fields.map(field => {
                  if (typeof field === 'string') {
            Severity: Minor
            Found in src/dialects/abstract/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 formatResults has 72 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

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

              Function run has 70 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async run(sql, parameters) {
                  const conn = this.connection;
                  this.sql = sql;
                  const method = this.getDatabaseMethod();
                  let complete;
              Severity: Major
              Found in src/dialects/sqlite/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 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 _validateIncludedElements has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      static _validateIncludedElements(options, tableNames) {
                        if (!options.model) options.model = this;
                    
                        tableNames = tableNames || {};
                        options.includeNames = [];
                    Severity: Major
                    Found in src/model.js - About 2 hrs to fix

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

                      module.exports = BaseTypes => {
                        BaseTypes.ABSTRACT.prototype.dialectTypes = 'https://mariadb.com/kb/en/library/resultset/#field-types';
                      
                        /**
                         * types: [buffer_type, ...]
                      Severity: Minor
                      Found in src/dialects/mariadb/data-types.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 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 findAll has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                      Open

                        static async findAll(options) {
                          if (options !== undefined && !_.isPlainObject(options)) {
                            throw new sequelizeErrors.QueryError(
                              'The argument passed to findAll must be an options object, use findByPk if you wish to pass a single primary key value'
                            );
                      Severity: Minor
                      Found in src/model.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 forEachModel has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                      Open

                        public forEachModel(iterator: (m: typeof Model) => void, options: { reverse: boolean } = { reverse: true }): void {
                          const models: Record<string, typeof Model> = {};
                          const sorter = new Toposort();
                      
                          for (const model of this.models) {
                      Severity: Minor
                      Found in src/model-manager.ts - 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

                      Severity
                      Category
                      Status
                      Source
                      Language