Skip to content

Commit 9ccf88c

Browse files
committed
Only cache prepared statement on successful parse
1 parent c7b12b2 commit 9ccf88c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/backend.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const char = (acc, [k, v]) => (acc[k.charCodeAt(0)] = v, acc)
66
export default Backend
77

88
function Backend({
9+
onparse,
910
onparameter,
1011
parsers,
1112
onauth,
@@ -53,7 +54,9 @@ function Backend({
5354

5455
return backend
5556

56-
function ParseComplete() { /* No handling needed */ }
57+
function ParseComplete() {
58+
onparse()
59+
}
5760
function BindComplete() { /* No handling needed */ }
5861
function CloseComplete() { /* No handling needed */ }
5962

lib/connection.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export default function Connection(options = {}) {
3434
})
3535

3636
const backend = Backend({
37+
onparse,
3738
onparameter,
3839
transform,
3940
parsers,
@@ -47,6 +48,11 @@ export default function Connection(options = {}) {
4748

4849
return connection
4950

51+
function onparse() {
52+
if (backend.query && backend.query.statement.name)
53+
statements[backend.query.statement.sig] = backend.query.statement.name
54+
}
55+
5056
function onauth(type, x) {
5157
socket.write(frontend.auth(type, x, options))
5258
}
@@ -109,8 +115,7 @@ export default function Connection(options = {}) {
109115
}
110116

111117
function prepare(sig, str, args, query) {
112-
query.statement = { name: sig ? 'p' + id++ : '' }
113-
sig && statements.set(sig, query.statement)
118+
query.statement = { name: sig ? 'p' + id++ : '', sig }
114119
return Buffer.concat([
115120
frontend.Parse(query.statement.name, str, args),
116121
frontend.Bind(query.statement.name, args)

0 commit comments

Comments
 (0)