sequelize/sequelize

View on GitHub

Showing 503 of 787 total issues

Function _refreshTypeParser has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  _refreshTypeParser(dataType) {
    const arrayParserBuilder = parser => {
      return value => this.lib.types.arrayParser.create(value, parser).parse();
    };
    const rangeParserBuilder = parser => {
Severity: Minor
Found in src/dialects/postgres/connection-manager.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

      Consider simplifying this complex logical expression.
      Open

          if (this.isInsertQuery() || this.isUpdateQuery() || this.isUpsertQuery()) {
            if (this.instance && this.instance.dataValues) {
              for (const key in rows[0]) {
                if (Object.prototype.hasOwnProperty.call(rows[0], key)) {
                  const record = rows[0][key];
      Severity: Critical
      Found in src/dialects/postgres/query.js - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

            if (isSQLServer2008 && options.offset) {
              // For earlier versions of SQL server, we need to nest several queries
              // in order to emulate the OFFSET behavior.
              //
              // 1. The outermost query selects all items from the inner query block.
        Severity: Critical
        Found in src/dialects/mssql/query-generator.js - About 1 hr to fix

          Function _singleAttrValidate has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async _singleAttrValidate(value, field, allowNull) {
              // If value is null and allowNull is false, no validators should run (see #9143)
              if ((value === null || value === undefined) && !allowNull) {
                // The schema validator (_validateSchema) has already generated the validation error. Nothing to do here.
                return;
          Severity: Minor
          Found in src/instance-validator.js - About 1 hr to fix

            Function sync has 33 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              async sync(options) {
                options = {
                  ...this.options,
                  ...this.options.sync,
                  ...options,
            Severity: Minor
            Found in src/sequelize.js - About 1 hr to fix

              Function renameColumnQuery has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                renameColumnQuery(tableName, attrNameBefore, attrNameAfter, attributes) {
                  let backupTableName;
              
                  attributes = this.attributesToSQL(attributes);
              
              
              Severity: Minor
              Found in src/dialects/sqlite/query-generator.js - About 1 hr to fix

                Function destroy has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  async destroy(options) {
                    options = {
                      hooks: true,
                      force: false,
                      ...options
                Severity: Minor
                Found in src/model.js - About 1 hr to fix

                  Function rawSelect has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    async rawSelect(tableName, options, attributeSelector, Model) {
                      options = Utils.cloneDeep(options);
                      options = _.defaults(options, {
                        raw: true,
                        plain: true,
                  Severity: Minor
                  Found in src/dialects/abstract/query-interface.js - About 1 hr to fix

                    Function _findSeparate has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      static async _findSeparate(results, options) {
                        if (!options.include || options.raw || !results) return results;
                    
                        const original = results;
                        if (options.plain) results = [results];
                    Severity: Minor
                    Found in src/model.js - About 1 hr to fix

                      Function arithmeticQuery has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        arithmeticQuery(operator, tableName, where, incrementAmountsByField, extraAttributesToBeUpdated, options) {
                          options = options || {};
                          _.defaults(options, { returning: true });
                      
                          extraAttributesToBeUpdated = Utils.removeNullValuesFromHash(extraAttributesToBeUpdated, this.options.omitNull);
                      Severity: Minor
                      Found in src/dialects/abstract/query-generator.js - About 1 hr to fix

                        Function fieldsSql has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            const fieldsSql = options.fields.map(field => {
                              if (field instanceof Utils.SequelizeMethod) {
                                return this.handleSequelizeMethod(field);
                              }
                              if (typeof field === 'string') {
                        Severity: Minor
                        Found in src/dialects/abstract/query-generator.js - About 1 hr to fix

                          Function _getIncludedAssociation has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            static _getIncludedAssociation(targetModel, targetAlias) {
                              const associations = this.getAssociations(targetModel);
                              let association = null;
                              if (associations.length === 0) {
                                throw new sequelizeErrors.EagerLoadingError(`${targetModel.name} is not associated to ${this.name}!`);
                          Severity: Minor
                          Found in src/model.js - About 1 hr to fix

                            Function forEachModel has 32 lines of code (exceeds 25 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 1 hr to fix

                              Function set has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                async set(sourceInstance, associatedInstance, options) {
                                  options = { ...options, scope: false };
                              
                                  const oldInstance = await sourceInstance[this.accessors.get](options);
                                  // TODO Use equals method once #5605 is resolved
                              Severity: Minor
                              Found in src/associations/has-one.js - About 1 hr to fix

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

                                  async sync(options) {
                                    options = {
                                      ...this.options,
                                      ...this.options.sync,
                                      ...options,
                                Severity: Minor
                                Found in src/sequelize.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 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 connect has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  async connect(config) {
                                    // Named timezone is not supported in mariadb, convert to offset
                                    let tzOffset = this.sequelize.options.timezone;
                                    tzOffset = /\//.test(tzOffset) ? momentTz.tz(tzOffset).format('Z') : tzOffset;
                                
                                
                                Severity: Minor
                                Found in src/dialects/mariadb/connection-manager.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 createTableQuery has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  createTableQuery(tableName, attributes, options) {
                                    options = { ...options };
                                
                                    //Postgres 9.0 does not support CREATE TABLE IF NOT EXISTS, 9.1 and above do
                                    const databaseVersion = _.get(this, 'sequelize.options.databaseVersion', 0);
                                Severity: Minor
                                Found in src/dialects/postgres/query-generator.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 _validateSchema has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                                Open

                                  _validateSchema(rawAttribute, field, value) {
                                    if (rawAttribute.allowNull === false && (value === null || value === undefined)) {
                                      const association = Object.values(this.modelInstance.constructor.associations).find(
                                        association => association instanceof BelongsTo && association.foreignKey === rawAttribute.fieldName
                                      );
                                Severity: Minor
                                Found in src/instance-validator.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

                                Severity
                                Category
                                Status
                                Source
                                Language