lib/sql-string.js
Function escape
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
Open
SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) {
if (arguments.length === 1 && typeof arguments[0] === "object") {
val = val.val || val.value || null
stringifyObjects = val.stringifyObjects || val.objects || undefined
timeZone = val.timeZone || val.zone || null
- Read upRead up
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 escape
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) {
if (arguments.length === 1 && typeof arguments[0] === "object") {
val = val.val || val.value || null
stringifyObjects = val.stringifyObjects || val.objects || undefined
timeZone = val.timeZone || val.zone || null
Function arrayToList
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
Open
SqlString.arrayToList = function(array, timeZone, dialect, field) {
if (dialect === 'postgres') {
if (array.map) {
var valstr = array.map(function(v) {
return SqlString.escape(v, true, timeZone, dialect, field)
- Read upRead up
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
Consider simplifying this complex logical expression. Open
Open
if (arguments.length === 1 && typeof arguments[0] === "object") {
val = val.val || val.value || null
stringifyObjects = val.stringifyObjects || val.objects || undefined
timeZone = val.timeZone || val.zone || null
dialect = val.dialect || null
Function arrayToList
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
SqlString.arrayToList = function(array, timeZone, dialect, field) {
if (dialect === 'postgres') {
if (array.map) {
var valstr = array.map(function(v) {
return SqlString.escape(v, true, timeZone, dialect, field)
Consider simplifying this complex logical expression. Open
Open
else if (arguments.length < 3 && typeof arguments[1] === "object") {
timeZone = stringifyObjects.timeZone || stringifyObjects.zone || null
dialect = stringifyObjects.dialect || null
field = stringifyObjects.field || null
}
Function escape
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
SqlString.escape = function(val, stringifyObjects, timeZone, dialect, field) {
Avoid too many return
statements within this function. Open
Open
return SqlString.objectToValues(newVal, timeZone)
Avoid too many return
statements within this function. Open
Open
return "'"+newVal+"'";
Avoid too many return
statements within this function. Open
Open
return "TO_TIMESTAMP_TZ('"+newVal+"','YYYY-MM-DD HH24:MI:SS.FF3 TZH:TZM')";