doix-db 1.0.30 → 1.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/DbClient.js +45 -3
- package/package.json +1 -1
package/lib/DbClient.js
CHANGED
|
@@ -130,7 +130,49 @@ class DbClient extends EventEmitter {
|
|
|
130
130
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
async do (
|
|
133
|
+
async do (q, params = [], options = {}) {
|
|
134
|
+
|
|
135
|
+
let sql
|
|
136
|
+
|
|
137
|
+
if (typeof q === 'string') {
|
|
138
|
+
|
|
139
|
+
sql = q
|
|
140
|
+
|
|
141
|
+
}
|
|
142
|
+
else if (Array.isArray (q)) {
|
|
143
|
+
|
|
144
|
+
const {length} = q; if (length === 0 || length > 2) throw Error ('Invalid `do` array parameter length: ' + length)
|
|
145
|
+
|
|
146
|
+
sql = q [0]
|
|
147
|
+
|
|
148
|
+
if (length === 2) params = q [1]
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
else if (typeof q === 'object') {
|
|
152
|
+
|
|
153
|
+
if ('sql' in q) {
|
|
154
|
+
|
|
155
|
+
sql = q.sql
|
|
156
|
+
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
|
|
160
|
+
throw Error ('Invalid `do` object parameter')
|
|
161
|
+
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if ('params' in q) {
|
|
165
|
+
|
|
166
|
+
params = q.params
|
|
167
|
+
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
|
|
173
|
+
throw Error ('Invalid `do` parameter: ' + q)
|
|
174
|
+
|
|
175
|
+
}
|
|
134
176
|
|
|
135
177
|
const call = this.call (sql, params, {
|
|
136
178
|
...options,
|
|
@@ -151,9 +193,9 @@ class DbClient extends EventEmitter {
|
|
|
151
193
|
|
|
152
194
|
return new Writable ({...options, objectMode: true,
|
|
153
195
|
|
|
154
|
-
write (
|
|
196
|
+
write (qp, _, callback) {
|
|
155
197
|
|
|
156
|
-
db.do (
|
|
198
|
+
db.do (qp).then (_ => callback (), callback)
|
|
157
199
|
|
|
158
200
|
}
|
|
159
201
|
|