Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4a785bf

Browse files
committedApr 8, 2020
Improve prepared statement name performance
1 parent 80a46e6 commit 4a785bf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎lib/connection.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ function Connection(options = {}) {
2424
let length = 0
2525
let messages = []
2626
let timer
27+
let statement_id = 1
2728
let ended
2829
let open = false
2930
let ready = false
@@ -32,6 +33,7 @@ function Connection(options = {}) {
3233

3334
const queries = Queue()
3435
, id = count++
36+
, uid = Math.random().toString(36).slice(2)
3537
, connection = { send, end, destroy }
3638

3739
const socket = postgresSocket(options, {
@@ -154,7 +156,7 @@ function Connection(options = {}) {
154156
}
155157

156158
function prepare(sig, str, args, query) {
157-
query.statement = { name: sig ? 'p' + Math.random().toString(30).slice(2) : '', sig }
159+
query.statement = { name: sig ? 'p' + uid + statement_id++ : '', sig }
158160
return Buffer.concat([
159161
frontend.Parse(query.statement.name, str, args),
160162
bind(query, args)

0 commit comments

Comments
 (0)
Failed to load comments.