Comparing version 1.0.16 to 1.0.17
@@ -16,4 +16,5 @@ //Low level connection to PostgreSQL database | ||
const Format = require('pg-format') //String formatting/escaping | ||
const RetryTimeout = 3000 //How long to wait for connection retry | ||
const RetryTimeout = 10000 //How long to wait for connection retry | ||
var initialize = true //Next user should try to init DB if necessary | ||
var connectQue = [] | ||
@@ -77,10 +78,25 @@ types.setTypeParser(1082, d=>(d)) //Don't convert simple dates to JS date/time | ||
this.client.connect(err => { //Make connection to DB for this client | ||
if (!err) {cb(); this.connecting = false; return} //Success | ||
if (!err) { //Success | ||
cb() //Call my callback | ||
this.connecting = false | ||
if (this.config.schema) while (connectQue.length > 0) { //Master responsible for reconnecting any other clients | ||
let { context, cb } = connectQue.shift() | ||
context.connect(cb) | ||
} | ||
return | ||
} | ||
this.log.debug("DB connection error:", err.message) | ||
let dbname = this.client.connectionParameters.database //DB we tried to connect to | ||
this.log.debug("DB connection error:", err.message) //Failed to connect | ||
let dbname = this.client.connectionParameters.database //Remember DB we tried to connect to | ||
this.disconnect() | ||
if (!this.config.schema && !this.config.retry) { //Let's retry in a couple seconds | ||
this.config.retry = true | ||
this.log.debug("Retrying:", this.config) | ||
if (!this.config.schema) { //Caller is not the master (has no ability to build schema) | ||
this.log.debug("Queing connection") | ||
connectQue.push({context:this, cb}) //Wait for master to connect | ||
return | ||
} | ||
if (!/database .* does not exist/.test(err.message)) { //Retry in a while | ||
if (!this.config.retry) this.config.retry = 0 | ||
this.log.debug("Retry", this.config.retry, "in:", RetryTimeout) | ||
this.config.retry++ | ||
setTimeout(()=>{this.connect(cb)}, RetryTimeout) | ||
@@ -90,5 +106,2 @@ return | ||
if (!/database .* does not exist/.test(err.message)) {fatal(err.message); return} //Abort on anything other than DB does not exist error | ||
if (!this.config.schema) {fatal('No schema found'); return} //No schema found to create | ||
let tclient = new Client(Object.assign({}, this.config, {database: DefaultDB})) | ||
@@ -117,3 +130,7 @@ tclient.connect(err => { //Try connecting to template DB | ||
this.connecting = false | ||
cb() //Success | ||
cb() //Success for this connection | ||
while (connectQue.length > 0) { //Now connect any other clients waiting for schema to build | ||
let { context, cb } = connectQue.shift() | ||
context.connect(cb) | ||
} | ||
}) //query to build schema | ||
@@ -120,0 +137,0 @@ }) //new client.connect |
@@ -218,2 +218,5 @@ //Manage the connection between a User Interface and the backend database | ||
parms.forEach((p,x)=>{ //node-pg tries to convert JS arrays to PS arrays. We don't want that. | ||
if (typeof p == 'object') parms[x] = JSON.stringify(p) | ||
}) | ||
ctx.db.query(query, parms, (err, res) => { //Run the user's query | ||
@@ -220,0 +223,0 @@ this.log.trace(" query:", query, "parms:", parms, "tuples:", tuples, "Err:", err) |
{ | ||
"name": "wyseman", | ||
"version": "1.0.16", | ||
"version": "1.0.17", | ||
"description": "PostgreSQL Schema Manager with Javascript, Ruby, TCL API", | ||
@@ -26,2 +26,3 @@ "main": "lib/index.js", | ||
"ticket": "bin/ticket", | ||
"wyseman-info": "bin/info.js", | ||
"wmdump": "bin/wmdump", | ||
@@ -33,10 +34,10 @@ "wmrestore": "bin/wmrestore", | ||
"dependencies": { | ||
"base64-js": "^1.3.0", | ||
"pg": "^7.9.0", | ||
"base64-js": "^1.3.1", | ||
"pg": "^7.14.0", | ||
"pg-format": "^1.0.4", | ||
"ws": "^6.2.1" | ||
"ws": "^7.2.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^5.2.0" | ||
"mocha": "^6.2.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
624901
69
670
+ Addedws@7.5.10(transitive)
- Removedasync-limiter@1.0.1(transitive)
- Removedws@6.2.3(transitive)
Updatedbase64-js@^1.3.1
Updatedpg@^7.14.0
Updatedws@^7.2.0