mythix-orm-postgresql 1.7.0 → 1.7.1
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/postgresql-connection.js +19 -23
- package/package.json +3 -3
|
@@ -123,7 +123,7 @@ class PostgreSQLConnection extends SQLConnectionBase {
|
|
|
123
123
|
return await this.query(...args);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
async query(_sql, _options) {
|
|
126
|
+
async query(_sql, _options, _client) {
|
|
127
127
|
let sql = _sql;
|
|
128
128
|
if (!sql)
|
|
129
129
|
return;
|
|
@@ -135,15 +135,15 @@ class PostgreSQLConnection extends SQLConnectionBase {
|
|
|
135
135
|
|
|
136
136
|
let options = _options || {};
|
|
137
137
|
let logger = options.logger || (this.getOptions().logger);
|
|
138
|
-
let
|
|
138
|
+
let hasOwnClient;
|
|
139
139
|
let client;
|
|
140
140
|
|
|
141
141
|
try {
|
|
142
|
-
client =
|
|
143
|
-
if (!client)
|
|
142
|
+
client = _client || this.inTransaction;
|
|
143
|
+
if (!client) {
|
|
144
144
|
client = await this.pool.connect();
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
hasOwnClient = true;
|
|
146
|
+
}
|
|
147
147
|
|
|
148
148
|
if (logger && sql.text)
|
|
149
149
|
console.log('QUERY: ', sql.text);
|
|
@@ -166,7 +166,7 @@ class PostgreSQLConnection extends SQLConnectionBase {
|
|
|
166
166
|
|
|
167
167
|
throw error;
|
|
168
168
|
} finally {
|
|
169
|
-
if (client &&
|
|
169
|
+
if (client && hasOwnClient)
|
|
170
170
|
await client.release();
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -198,46 +198,42 @@ class PostgreSQLConnection extends SQLConnectionBase {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
if (!inheritedThis.inTransaction) {
|
|
201
|
-
client =
|
|
202
|
-
if (!client)
|
|
203
|
-
client = await inheritedThis.pool.connect();
|
|
204
|
-
|
|
205
|
-
inheritedThis.inTransaction = client;
|
|
201
|
+
client = inheritedThis.inTransaction = await inheritedThis.pool.connect();
|
|
206
202
|
|
|
207
203
|
try {
|
|
208
|
-
await inheritedThis.query(`BEGIN${(options.beginArguments) ? ` ${options.beginArguments}` : ''}`, options);
|
|
204
|
+
await inheritedThis.query(`BEGIN${(options.beginArguments) ? ` ${options.beginArguments}` : ''}`, options, client);
|
|
209
205
|
if (lockStatement)
|
|
210
|
-
await inheritedThis.query(lockStatement, options);
|
|
206
|
+
await inheritedThis.query(lockStatement, options, client);
|
|
211
207
|
|
|
212
208
|
// TODO: Need to handle "busy" error
|
|
213
209
|
} catch (error) {
|
|
214
|
-
|
|
215
|
-
await client.release();
|
|
216
|
-
|
|
210
|
+
await client.release();
|
|
217
211
|
throw error;
|
|
218
212
|
}
|
|
219
213
|
} else {
|
|
214
|
+
client = inheritedThis.inTransaction;
|
|
215
|
+
|
|
220
216
|
savePointName = inheritedThis.generateSavePointName();
|
|
221
217
|
inheritedThis.savePointName = savePointName;
|
|
222
218
|
inheritedThis.isSavePoint = true;
|
|
223
219
|
|
|
224
|
-
await inheritedThis.query(`SAVEPOINT ${savePointName}`, options);
|
|
220
|
+
await inheritedThis.query(`SAVEPOINT ${savePointName}`, options, client);
|
|
225
221
|
}
|
|
226
222
|
|
|
227
223
|
try {
|
|
228
224
|
let result = await inheritedThis.createContext(callback, inheritedThis, inheritedThis);
|
|
229
225
|
|
|
230
226
|
if (savePointName)
|
|
231
|
-
await inheritedThis.query(`RELEASE SAVEPOINT ${savePointName}`, options);
|
|
227
|
+
await inheritedThis.query(`RELEASE SAVEPOINT ${savePointName}`, options, client);
|
|
232
228
|
else
|
|
233
|
-
await inheritedThis.query('COMMIT', options);
|
|
229
|
+
await inheritedThis.query('COMMIT', options, client);
|
|
234
230
|
|
|
235
231
|
return result;
|
|
236
232
|
} catch (error) {
|
|
237
233
|
if (savePointName)
|
|
238
|
-
await inheritedThis.query(`ROLLBACK TO SAVEPOINT ${savePointName}`, options);
|
|
239
|
-
else
|
|
240
|
-
await inheritedThis.query('ROLLBACK', options);
|
|
234
|
+
await inheritedThis.query(`ROLLBACK TO SAVEPOINT ${savePointName}`, options, client);
|
|
235
|
+
else
|
|
236
|
+
await inheritedThis.query('ROLLBACK', options, client);
|
|
241
237
|
|
|
242
238
|
throw error;
|
|
243
239
|
} finally {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix-orm-postgresql",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"description": "PostgreSQL driver for Mythix ORM",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"homepage": "https://github.com/th317erd/mythix-orm-postgresql#readme",
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"mythix-orm": "^1.8.
|
|
37
|
-
"mythix-orm-sql-base": "^1.7.
|
|
36
|
+
"mythix-orm": "^1.8.1",
|
|
37
|
+
"mythix-orm-sql-base": "^1.7.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"luxon": "^3.0.4",
|