Skip to content

Commit b7a2356

Browse files
committed
simpler query
1 parent bd06582 commit b7a2356

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

packages/pg/lib/query.js

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,47 @@ class Query {
77
constructor(config, values, callback) {
88
config = utils.normalizeQueryConfig(config, values, callback)
99

10-
this.text = config.text
11-
this.values = config.values
12-
this.rows = config.rows
13-
this.types = config.types
14-
this.name = config.name
15-
this.queryMode = config.queryMode
16-
this.binary = config.binary
17-
// use unique portal name each time
18-
this.portal = config.portal || ''
19-
this.callback = config.callback
20-
this._rowMode = config.rowMode
21-
if (process.domain && config.callback) {
22-
this.callback = process.domain.bind(config.callback)
23-
}
24-
this._result = new Result(this._rowMode, this.types)
10+
this._config = config
11+
12+
if (typeof values === 'function') {
13+
callback = values
14+
values = undefined
15+
}
16+
this.values = values || config.values
17+
18+
if (callback) {
19+
this.callback = callback || config.callback
20+
}
21+
22+
this._result = new Result(this._config.rowMode, this.types)
2523

2624
// potential for multiple results
2725
this._results = this._result
2826
this._canceledDueToError = false
2927
}
3028

29+
get text() {
30+
return this._config.text
31+
}
32+
get rows() {
33+
return this._config.rows
34+
}
35+
get types() {
36+
return this._config.types
37+
}
38+
get name() {
39+
return this._config.name
40+
}
41+
get queryMode() {
42+
return this._config.queryMode
43+
}
44+
get binary() {
45+
return this._config.binary
46+
}
47+
get portal() {
48+
return this._config.portal || ''
49+
}
50+
3151
requiresPreparation() {
3252
if (this.queryMode === 'extended') {
3353
return true
@@ -61,7 +81,7 @@ class Query {
6181
if (!Array.isArray(this._results)) {
6282
this._results = [this._result]
6383
}
64-
this._result = new Result(this._rowMode, this.types)
84+
this._result = new Result(this._config.rowMode, this.types)
6585
this._results.push(this._result)
6686
}
6787
}
@@ -72,7 +92,6 @@ class Query {
7292
handleRowDescription(msg) {
7393
this._checkForMultirow()
7494
this._result.addFields(msg.fields)
75-
this._accumulateRows = this.callback || !this.listeners('row').length
7695
}
7796

7897
handleDataRow(msg) {
@@ -89,9 +108,9 @@ class Query {
89108
return
90109
}
91110

92-
if (this._accumulateRows) {
111+
//if (this.callback) {
93112
this._result.addRow(row)
94-
}
113+
//}
95114
}
96115

97116
handleCommandComplete(msg, connection) {

packages/pg/lib/utils.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,10 @@ function dateToStringUTC(date) {
155155
return ret
156156
}
157157

158-
function normalizeQueryConfig(config, values, callback) {
158+
function normalizeQueryConfig(config) {
159159
// can take in strings or config objects
160160
config = typeof config === 'string' ? { text: config } : config
161-
if (values) {
162-
if (typeof values === 'function') {
163-
config.callback = values
164-
} else {
165-
config.values = values
166-
}
167-
}
168-
if (callback) {
169-
config.callback = callback
170-
}
161+
171162
return config
172163
}
173164

0 commit comments

Comments
 (0)