@brainsights/postgres-wrapper
Advanced tools
Comparing version 1.0.0 to 1.0.1
27
index.js
const pg = require("pg"); | ||
const SQL = require("sql-template-strings"); | ||
const debug = require("debug")("postgres-wrapper"); | ||
const uuid = require("uuid"); | ||
let types = pg.types; | ||
types.setTypeParser(20, function(val) { | ||
return parseInt(val) | ||
}); | ||
const __ = new WeakMap(); | ||
@@ -17,3 +23,4 @@ | ||
__.set(proxy, { | ||
revoke: revoke | ||
revoke: revoke, | ||
id: uuid.v4(), | ||
}); | ||
@@ -29,3 +36,3 @@ return proxy; | ||
client = await pool.connect(); | ||
debug("acquire client"); | ||
debug(`${this.id} acquire client`); | ||
} catch(e) { | ||
@@ -40,2 +47,3 @@ throw new Error(`unable to get database client: ${e.message}`) | ||
result = await __.get(this).client.query(...args); | ||
debug(`${this.id} query`) | ||
} catch(e) { | ||
@@ -50,6 +58,11 @@ throw new Error(`query failed: ${e.message}`) | ||
{ | ||
debug("release client"); | ||
debug(`${__.get(this).id} release client`); | ||
__.get(this).client.end(); | ||
__.get(this).revoke(); | ||
} | ||
get id() | ||
{ | ||
return __.get(this).id; | ||
} | ||
}; | ||
@@ -70,7 +83,7 @@ | ||
await super.query(SQL`BEGIN`); | ||
debug("begin transaction"); | ||
debug(`${this.id} begin transaction`); | ||
} catch(e) { | ||
throw new Error(`unable to start transaction: ${e.message}`); | ||
__.get(this).revoke(); | ||
debug("revoke transaction object"); | ||
debug(`${this.id} revoke transaction object`); | ||
} | ||
@@ -86,3 +99,3 @@ __.get(this).begin = true; | ||
await this.query(SQL`COMMIT`); | ||
debug("commit transaction"); | ||
debug(`${this.id} commit transaction`); | ||
super.end(); | ||
@@ -94,3 +107,3 @@ } | ||
await this.query(SQL`ROLLBACK`); | ||
debug("abort transaction"); | ||
debug(`${this.id} abort transaction`); | ||
super.end(); | ||
@@ -97,0 +110,0 @@ } |
{ | ||
"name": "@brainsights/postgres-wrapper", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -15,5 +15,5 @@ "main": "index.js", | ||
"pg": "^6.1.4", | ||
"pg-native": "^1.10.0", | ||
"sql-template-strings": "^2.2.2" | ||
"sql-template-strings": "^2.2.2", | ||
"uuid": "^3.0.1" | ||
} | ||
} |
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
2636
93
+ Addeduuid@^3.0.1
+ Addeduuid@3.4.0(transitive)
- Removedpg-native@^1.10.0
- Removedbindings@1.5.0(transitive)
- Removedcore-util-is@1.0.3(transitive)
- Removedfile-uri-to-path@1.0.0(transitive)
- Removedinherits@2.0.4(transitive)
- Removedisarray@0.0.1(transitive)
- Removedlibpq@1.8.13(transitive)
- Removednan@2.19.0(transitive)
- Removedpg-native@1.10.1(transitive)
- Removedpg-types@1.6.0(transitive)
- Removedreadable-stream@1.0.31(transitive)
- Removedstring_decoder@0.10.31(transitive)