Skip to content

Commit d53cb01

Browse files
committed
Add logging debug option
1 parent 88ce80b commit d53cb01

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lib/connection.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const { errors } = require('./types.js')
77

88
module.exports = Connection
99

10+
let count = 1
11+
1012
function Connection(options = {}) {
1113
const {
1214
onparameter,
@@ -21,12 +23,13 @@ function Connection(options = {}) {
2123
let length = 0
2224
let messages = []
2325
let timer
24-
let id = 1
26+
let statement_id = 1
2527
let ended
2628
let ready = false
2729
let statements = {}
2830

2931
const queries = Queue()
32+
, id = count++
3033
, connection = { send, end, destroy }
3134

3235
const socket = postgresSocket(options, {
@@ -87,6 +90,7 @@ function Connection(options = {}) {
8790
query.result.count = null
8891
timeout && clearTimeout(timer)
8992

93+
options.debug && options.debug(id, str, args)
9094
const buffer = query.simple
9195
? simple(str, query)
9296
: sig in statements
@@ -113,7 +117,7 @@ function Connection(options = {}) {
113117
}
114118

115119
function prepare(sig, str, args, query) {
116-
query.statement = { name: sig ? 'p' + id++ : '', sig }
120+
query.statement = { name: sig ? 'p' + statement_id++ : '', sig }
117121
return Buffer.concat([
118122
frontend.Parse(query.statement.name, str, args),
119123
frontend.Bind(query.statement.name, args)

lib/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ function parseOptions(uri = {}, options) {
470470
nonce : crypto.randomBytes(18).toString('base64'),
471471
transform : { ...o.transform },
472472
connection : { application_name: 'postgres.js', ...o.connection },
473+
debug : o.debug,
473474
...mergeUserTypes(o.types)
474475
}
475476
}

0 commit comments

Comments
 (0)