waterlinejs/postgresql-adapter

View on GitHub

Showing 16 of 16 total issues

File adapter.js has 366 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import Knex from 'knex'
import _ from 'lodash'
import camelize from 'camelize'
import WaterlineSequel from 'waterline-sequel'

Severity: Minor
Found in lib/adapter.js - About 4 hrs to fix

    File util.js has 350 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import _ from 'lodash'
    import Adapter from './adapter'
    import CriteriaParser from 'waterline-sequel/sequel/lib/criteriaProcessor'
    import SpatialUtil from './spatial'
    import Procedures from './procedures'
    Severity: Minor
    Found in lib/util.js - About 4 hrs to fix

      Util has 27 functions (exceeds 20 allowed). Consider refactoring.
      Open

      const Util = {
      
        PG_MAX_INT: 2147483647,
      
        initializeConnection (cxn) {
      Severity: Minor
      Found in lib/util.js - About 3 hrs to fix

        Function toKnexColumn has 76 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          toKnexColumn (table, _name, attrDefinition, wlModel, schema) {
            let attr = _.isObject(attrDefinition) ? attrDefinition : { type: attrDefinition }
            let type = attr.autoIncrement ? 'serial' : attr.type
            let name = attr.columnName || _name
        
        
        Severity: Major
        Found in lib/util.js - About 3 hrs to fix

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

            validateVersion ([ major, minor, patch ]) {
              if (major < 9 || (major === 9 && minor < 4)) {
                throw new Error(`
                  PostgreSQL ${major}.${minor}.${patch} detected. This adapter requires PostgreSQL 9.4 or higher.
                  Please either:
          Severity: Major
          Found in lib/util.js and 1 other location - About 2 hrs to fix
          lib/spatial.js on lines 22..33

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

          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

            validatePostgisVersion ([ major, minor, patch ]) {
              if (major < 2 || (major == 2 && minor < 1)) {
                throw new Error(`
                  PostGIS ${major}.${minor}.${patch} detected. This adapter requires PostGIS 2.1 or higher.
                  Please either:
          Severity: Major
          Found in lib/spatial.js and 1 other location - About 2 hrs to fix
          lib/util.js on lines 533..544

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

          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

          Adapter has 23 functions (exceeds 20 allowed). Consider refactoring.
          Open

          const Adapter = {
          
            identity: 'waterline-postgresql',
          
            wlSqlOptions: {
          Severity: Minor
          Found in lib/adapter.js - About 2 hrs to fix

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

              toKnexColumn (table, _name, attrDefinition, wlModel, schema) {
                let attr = _.isObject(attrDefinition) ? attrDefinition : { type: attrDefinition }
                let type = attr.autoIncrement ? 'serial' : attr.type
                let name = attr.columnName || _name
            
            
            Severity: Minor
            Found in lib/util.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 applyParticularColumnConstraint has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

              applyParticularColumnConstraint (column, constraintName, value, definition) {
                if (!value) return
            
                switch (constraintName) {
            
            
            Severity: Minor
            Found in lib/util.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 registerConnection has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              registerConnection (connection, collections, cb) {
                if (!connection.identity) {
                  return cb(WaterlineError.adapter.IdentityMissing)
                }
                if (Adapter.connections.get(connection.identity)) {
            Severity: Minor
            Found in lib/adapter.js - About 1 hr to fix

              Function addAttribute has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                addAttribute (connectionName, tableName, attributeName, definition, cb) {
              Severity: Minor
              Found in lib/adapter.js - About 35 mins to fix

                Function query has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  query (connectionName, tableName, queryString, args, cb) {
                Severity: Minor
                Found in lib/adapter.js - About 35 mins to fix

                  Function update has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    update (connectionName, tableName, options, data, cb) {
                  Severity: Minor
                  Found in lib/adapter.js - About 35 mins to fix

                    Function toKnexColumn has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      toKnexColumn (table, _name, attrDefinition, wlModel, schema) {
                    Severity: Minor
                    Found in lib/util.js - About 35 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return column.defaultTo(knex.raw('uuid_generate_v4()'))
                      Severity: Major
                      Found in lib/util.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                              return value
                        Severity: Major
                        Found in lib/util.js - About 30 mins to fix
                          Severity
                          Category
                          Status
                          Source
                          Language