Comparing version 1.0.2 to 1.0.3
@@ -6,2 +6,5 @@ //Manage the connection between a User Interface and the backend database | ||
//X- Works with dbclient | ||
//- Should any of the %s's in pg-format really be %L's? | ||
//- Allow to specify 'returning' fields to insert, update overriding default * | ||
//- Handle warnings from the database, in addition to errors? (like if row count = 0) | ||
//- Query to return meta-data for table joins | ||
@@ -14,3 +17,3 @@ //- How to handle module-specific control functions? | ||
const Format = require('pg-format') //String formatting/escaping | ||
const Opers = ['=', '!=', '<', '<=', '>', '>=', '~', 'in', 'is'] | ||
const Opers = ['=', '!=', '<', '<=', '>', '>=', '~', 'diff', 'in', 'null', 'true'] | ||
@@ -90,3 +93,3 @@ module.exports = class Wyseman { | ||
this.db.query(qstring, parms, (err, res) => { //Run the user's query | ||
this.log.trace(" qstring:", qstring, "parms:", parms, "tuples:", tuples) | ||
this.log.debug(" query:", qstring, "parms:", parms, "tuples:", tuples, "Err:", err) | ||
if (err) { | ||
@@ -186,2 +189,3 @@ msg.error = this.error("from database", err) | ||
Object.keys(fields).forEach(fld => { | ||
if (fld === null || fld === undefined) {res.error = this.error("invalid null or undefined field", 'badFieldName'); return null} | ||
flist.push(Format("%I", fld)) | ||
@@ -208,2 +212,3 @@ plist.push(Format("$%s", i++)) | ||
Object.keys(fields).forEach(fld => { | ||
if (fld === null || fld === undefined) {res.error = this.error("invalid null or undefined field", 'badFieldName'); return null} | ||
flist.push(Format("%I = $%s", fld, i++)) | ||
@@ -241,2 +246,3 @@ res.parms.push(fields[fld]) | ||
//this.log.trace("Left:", left, "Oper:", oper, "Right:", right) | ||
if (left === null || left === undefined) {res.error = this.error("invalid null or undefined left hand side", 'badLeftSide'); return null} | ||
if (!Opers.includes(oper)) {res.error = this.error("invalid operator: " + oper, 'badOperator'); return null} | ||
@@ -248,6 +254,7 @@ clauses.push(Format("%I %s $%s", left, oper, i++)) | ||
} else if ('items' in logic) { //Logic list syntax | ||
} else if ('items' in logic) { //Logic list syntax | ||
if (!('and' in logic)) logic.and = true //Default to 'and' combiner | ||
let clauses = []; logic.items.forEach((item) => { | ||
clauses.push(this.buildWhere(item, res)) | ||
let clause = this.buildWhere(item, res) | ||
if (clause) clauses.push(clause) | ||
}) | ||
@@ -257,6 +264,23 @@ return clauses.join(logic.and ? ' and ' : ' or ') | ||
} else if ('left' in logic) { //Logic clause syntax | ||
if (logic.oper == 'nop') return null | ||
let oper = logic.oper || '=' | ||
if (logic.left === null || logic.left === undefined) {res.error = this.error("invalid null or undefined field", 'badFieldName'); return null} | ||
if (!Opers.includes(oper)) {res.error = this.error("invalid operator: " + oper, 'badOperator'); return null} | ||
res.parms.push(logic.entry || logic.right || '') | ||
return Format("%I %s $%s", logic.left, oper, i++) | ||
if (logic.oper == 'diff') logic.oper = 'is distinct from' | ||
if (logic.oper == 'null') { | ||
return Format("%s(%I is null)", logic.not ? 'not ' : '', logic.left) | ||
} else if (logic.oper == 'true') { | ||
return Format("%s%I", logic.not ? 'not ' : '', logic.left) | ||
} else if (logic.oper == 'in') { | ||
if (logic.entry) { | ||
return Format("%s(%I in (%L))", logic.not ? 'not ' : '', logic.left, logic.entry.split(',')) | ||
} else if (logic.right) { | ||
return Format("%s(%I = any(%I))", logic.not ? 'not ' : '', logic.left, logic.right) | ||
} else { | ||
res.error = this.error("invalid or null right side", 'badRight'); return null | ||
} | ||
} else { | ||
res.parms.push(logic.entry || logic.right || '') | ||
return Format("%s(%I %s $%s)", logic.not ? 'not ' : '', logic.left, oper, i++) | ||
} | ||
@@ -284,2 +308,4 @@ } else if (typeof logic == 'object') { //Compact form, each key is an = clause, anded together | ||
if (typeof el == 'object') { | ||
let col = el.field || el.column || el.columnId | ||
if (col === null || col === undefined) {res.error = this.error("invalid null or undefined field", 'badFieldName'); return null} | ||
ords.push(Format("%I %s", el.field || el.column || el.columnId, (el.asc || el.sortAsc) ? 'asc' : 'desc')) | ||
@@ -286,0 +312,0 @@ } else if (typeof el == 'number') { |
{ | ||
"name": "wyseman", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "PostgreSQL Schema Manager with Javascript, Ruby, TCL API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
600681
476