pqb 0.66.3 → 0.66.4
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/dist/index.d.ts +33 -13
- package/dist/index.js +65 -52
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -52
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/node-postgres.js +59 -14
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +59 -14
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.js +52 -18
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +53 -19
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4093,8 +4093,8 @@ const checkIfNeedResultAllForMutativeQueriesSelectRelations = (sql) => {
|
|
|
4093
4093
|
const checkIfShouldReleaseSavepointForMutativeQueriesSelectRelations = (sql) => {
|
|
4094
4094
|
return sql.mutativeQueriesSelectRelationsState?.value;
|
|
4095
4095
|
};
|
|
4096
|
-
const loadMutativeQueriesSelectRelations = (sql, result,
|
|
4097
|
-
const loadRelations = async (state, result,
|
|
4096
|
+
const loadMutativeQueriesSelectRelations = (sql, result, savepointState, renames) => sql.mutativeQueriesSelectRelationsState?.value ? loadRelations(sql.mutativeQueriesSelectRelationsState, result, savepointState, renames) : void 0;
|
|
4097
|
+
const loadRelations = async (state, result, savepointState, renames) => {
|
|
4098
4098
|
const q = state.query;
|
|
4099
4099
|
const primaryKeys = requirePrimaryKeys(q, "Cannot select a relation of a table that has no primary keys");
|
|
4100
4100
|
const selectQuery = _unscope(q, "nonDeleted");
|
|
@@ -4117,9 +4117,9 @@ const loadRelations = async (state, result, adapter, startingSavepoint, renames)
|
|
|
4117
4117
|
});
|
|
4118
4118
|
selectQuery.q.select = select;
|
|
4119
4119
|
const relationsResult = await maybeWrappedThen.call(selectQuery, void 0, async (err) => {
|
|
4120
|
-
await
|
|
4120
|
+
await savepointState?.activeSavepoint?.rollback(err);
|
|
4121
4121
|
throw err;
|
|
4122
|
-
},
|
|
4122
|
+
}, savepointState);
|
|
4123
4123
|
for (const row of result) {
|
|
4124
4124
|
const relationRow = relationsResult.find((relationRow) => {
|
|
4125
4125
|
return !primaryKeys.some((key, i) => relationRow[relationKeyAliases[i]] !== row[key]);
|
|
@@ -4244,7 +4244,7 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4244
4244
|
let queryResult;
|
|
4245
4245
|
let cteData;
|
|
4246
4246
|
const startingSavepoint = setCatchingSavepoint(!parentSavepoint && shouldCatch && state);
|
|
4247
|
-
const releasingSavepoint = checkIfShouldReleaseSavepointForMutativeQueriesSelectRelations(sql) || parentSavepoint ? void 0 : startingSavepoint;
|
|
4247
|
+
const releasingSavepoint = checkIfShouldReleaseSavepointForMutativeQueriesSelectRelations(sql) || parentSavepoint ? void 0 : parentSavepoint || startingSavepoint;
|
|
4248
4248
|
if ("text" in sql) {
|
|
4249
4249
|
if (query.autoPreparedStatements) sql.name = queriesNames[sql.text] || (queriesNames[sql.text] = (nameI++).toString(36));
|
|
4250
4250
|
if (log) logData = log.beforeQuery(sql);
|
|
@@ -4419,7 +4419,7 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4419
4419
|
}
|
|
4420
4420
|
}
|
|
4421
4421
|
}
|
|
4422
|
-
const promise = loadMutativeQueriesSelectRelations(localSql, result,
|
|
4422
|
+
const promise = loadMutativeQueriesSelectRelations(localSql, result, startingSavepoint, renames) || parseBatch(q, queryResult);
|
|
4423
4423
|
if (promise) await promise;
|
|
4424
4424
|
if (tableHook?.select || tempReturnType !== returnType) {
|
|
4425
4425
|
if (renames) {
|
|
@@ -4465,7 +4465,10 @@ const then = async (q, adapter, state, beforeHooks, afterHooks, afterSaveHooks,
|
|
|
4465
4465
|
}
|
|
4466
4466
|
};
|
|
4467
4467
|
const setCatchingSavepoint = (catchTrx) => {
|
|
4468
|
-
return catchTrx
|
|
4468
|
+
return catchTrx && catchTrx.transactionAdapter ? {
|
|
4469
|
+
transactionAdapter: catchTrx.transactionAdapter,
|
|
4470
|
+
name: `s${catchTrx.catchI = (catchTrx.catchI || 0) + 1}`
|
|
4471
|
+
} : void 0;
|
|
4469
4472
|
};
|
|
4470
4473
|
/**
|
|
4471
4474
|
* Executes a query and in the case there are rows, but nothing was selected,
|
|
@@ -4473,7 +4476,17 @@ const setCatchingSavepoint = (catchTrx) => {
|
|
|
4473
4476
|
* because user might expect empty objects to be returned for an empty select.
|
|
4474
4477
|
*/
|
|
4475
4478
|
const execQuery = (adapter, method, sql, startingSavepoint, releasingSavepoint, sqlSessionState) => {
|
|
4476
|
-
|
|
4479
|
+
let promise;
|
|
4480
|
+
if (startingSavepoint) if (releasingSavepoint) promise = startingSavepoint.transactionAdapter.savepoint(startingSavepoint.name, () => {
|
|
4481
|
+
return promise = adapter[method](sql.text, sql.values, sqlSessionState);
|
|
4482
|
+
});
|
|
4483
|
+
else promise = startingSavepoint.transactionAdapter.hackySavepoint(startingSavepoint, sql.text, sql.values, method === "arrays");
|
|
4484
|
+
else promise = adapter[method](sql.text, sql.values, sqlSessionState);
|
|
4485
|
+
if (!startingSavepoint && releasingSavepoint) promise = promise.then(async (res) => {
|
|
4486
|
+
await releasingSavepoint.activeSavepoint?.release();
|
|
4487
|
+
return res;
|
|
4488
|
+
});
|
|
4489
|
+
return promise.then((result) => {
|
|
4477
4490
|
if (result.rowCount && !result.rows.length) {
|
|
4478
4491
|
result.rows.length = result.rowCount;
|
|
4479
4492
|
result.rows.fill({});
|
|
@@ -13217,7 +13230,7 @@ const performQuery = async (q, args, method) => {
|
|
|
13217
13230
|
let logData;
|
|
13218
13231
|
if (log) logData = log.beforeQuery(sql);
|
|
13219
13232
|
try {
|
|
13220
|
-
const result = await (trx?.transactionAdapter || q.adapterNotInTransaction)[method](sql.text, sql.values,
|
|
13233
|
+
const result = await (trx?.transactionAdapter || q.adapterNotInTransaction)[method](sql.text, sql.values, sqlSessionContextGetStateFromAsyncState(trx));
|
|
13221
13234
|
if (log) log.afterQuery(sql, logData);
|
|
13222
13235
|
return result;
|
|
13223
13236
|
} catch (err) {
|
|
@@ -13667,11 +13680,11 @@ var AdapterClass = class AdapterClass {
|
|
|
13667
13680
|
this.pool = this.driverAdapter.configure(this.config);
|
|
13668
13681
|
this.errorClass = this.driverAdapter.errorClass;
|
|
13669
13682
|
}
|
|
13670
|
-
query(text, values,
|
|
13671
|
-
return runQueryHandlePool(this.pool, this.driverAdapter, text, values,
|
|
13683
|
+
query(text, values, sqlSessionState) {
|
|
13684
|
+
return runQueryHandlePool(this.pool, this.driverAdapter, text, values, sqlSessionState);
|
|
13672
13685
|
}
|
|
13673
|
-
arrays(text, values,
|
|
13674
|
-
return runQueryHandlePool(this.pool, this.driverAdapter, text, values,
|
|
13686
|
+
arrays(text, values, sqlSessionState) {
|
|
13687
|
+
return runQueryHandlePool(this.pool, this.driverAdapter, text, values, sqlSessionState, true);
|
|
13675
13688
|
}
|
|
13676
13689
|
clone(params) {
|
|
13677
13690
|
return new AdapterClass({
|
|
@@ -13715,13 +13728,13 @@ var TransactionAdapterClass = class {
|
|
|
13715
13728
|
this.driverAdapter = adapter.driverAdapter;
|
|
13716
13729
|
this.errorClass = this.adapter.errorClass;
|
|
13717
13730
|
}
|
|
13718
|
-
query(text, values,
|
|
13731
|
+
query(text, values, sqlSessionState) {
|
|
13719
13732
|
const setup = sqlSessionContextComputeSetup(sqlSessionState);
|
|
13720
|
-
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values,
|
|
13733
|
+
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values, setup);
|
|
13721
13734
|
}
|
|
13722
|
-
arrays(text, values,
|
|
13735
|
+
arrays(text, values, sqlSessionState) {
|
|
13723
13736
|
const setup = sqlSessionContextComputeSetup(sqlSessionState);
|
|
13724
|
-
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values,
|
|
13737
|
+
return runQueryHandleSetupAndCleanup(this.driverAdapter, this.client, text, values, setup, true);
|
|
13725
13738
|
}
|
|
13726
13739
|
clone(params) {
|
|
13727
13740
|
return this.adapter.clone(params);
|
|
@@ -13747,6 +13760,16 @@ var TransactionAdapterClass = class {
|
|
|
13747
13760
|
async transaction(asyncStorage, options, cb) {
|
|
13748
13761
|
return transaction(asyncStorage, this.adapter, this.driverAdapter, this.client, options, cb, this);
|
|
13749
13762
|
}
|
|
13763
|
+
savepoint(name, cb) {
|
|
13764
|
+
return this.driverAdapter.savepoint(this.client, (client) => {
|
|
13765
|
+
this.client = client;
|
|
13766
|
+
}, name, cb);
|
|
13767
|
+
}
|
|
13768
|
+
hackySavepoint(state, text, values, arraysMode) {
|
|
13769
|
+
return this.driverAdapter.hackySavepoint(this.client, (client) => {
|
|
13770
|
+
this.client = client;
|
|
13771
|
+
}, state, text, values, arraysMode);
|
|
13772
|
+
}
|
|
13750
13773
|
close() {
|
|
13751
13774
|
return this.adapter.close();
|
|
13752
13775
|
}
|
|
@@ -13764,7 +13787,7 @@ const transaction = (asyncStorage, adapter, driverAdapter, poolOrClient, options
|
|
|
13764
13787
|
};
|
|
13765
13788
|
const transactionId = state?.transactionId !== void 0 ? state.transactionId + 1 : 0;
|
|
13766
13789
|
const fn = (transactionAdapter) => {
|
|
13767
|
-
if (log) log.afterQuery(sql, ctx.logData);
|
|
13790
|
+
if (log && sql.text) log.afterQuery(sql, ctx.logData);
|
|
13768
13791
|
if (log) ctx.logData = log.beforeQuery(commitSql);
|
|
13769
13792
|
if (state || !asyncStorage) {
|
|
13770
13793
|
const parentTransactionRole = state?.transactionRole;
|
|
@@ -13799,7 +13822,7 @@ const transaction = (asyncStorage, adapter, driverAdapter, poolOrClient, options
|
|
|
13799
13822
|
return asyncStorage.run(ctx.state, () => cb(transactionAdapter));
|
|
13800
13823
|
};
|
|
13801
13824
|
transactionAdapter ??= state?.transactionAdapter;
|
|
13802
|
-
if (transactionAdapter) return nestedTransaction(adapter, driverAdapter, transactionAdapter, poolOrClient, options, fn, ctx, transactionId
|
|
13825
|
+
if (transactionAdapter) return nestedTransaction(adapter, driverAdapter, transactionAdapter, poolOrClient, options, fn, ctx, transactionId);
|
|
13803
13826
|
else return realTransaction(adapter, driverAdapter, poolOrClient, options, fn, ctx, sql, log);
|
|
13804
13827
|
};
|
|
13805
13828
|
const realTransaction = async (adapter, driverAdapter, pool, options, cb, ctx, sql, log) => {
|
|
@@ -13833,36 +13856,26 @@ const realTransaction = async (adapter, driverAdapter, pool, options, cb, ctx, s
|
|
|
13833
13856
|
if (ctx.state) runAfterCommit(ctx.state.afterCommit, result);
|
|
13834
13857
|
return result;
|
|
13835
13858
|
};
|
|
13836
|
-
const nestedTransaction = async (adapter, driverAdapter, transactionAdapter, client, options, cb, ctx, transactionId
|
|
13859
|
+
const nestedTransaction = async (adapter, driverAdapter, transactionAdapter, client, options, cb, ctx, transactionId) => {
|
|
13837
13860
|
const state = ctx.state;
|
|
13838
13861
|
const parentRole = state?.transactionRole;
|
|
13839
13862
|
const parentSetConfig = state?.transactionSetConfig;
|
|
13840
|
-
|
|
13841
|
-
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
|
|
13845
|
-
|
|
13846
|
-
|
|
13847
|
-
|
|
13848
|
-
|
|
13849
|
-
|
|
13850
|
-
|
|
13851
|
-
|
|
13852
|
-
|
|
13853
|
-
|
|
13854
|
-
|
|
13855
|
-
|
|
13856
|
-
} finally {
|
|
13857
|
-
const resetRoleSql = getResetRoleSql(parentRole, options);
|
|
13858
|
-
if (resetRoleSql) await driverAdapter.queryClient(client, resetRoleSql);
|
|
13859
|
-
}
|
|
13860
|
-
const resetSetConfigSql = getResetSetConfigSql(parentSetConfig, options);
|
|
13861
|
-
if (resetSetConfigSql) driverAdapter.queryClient(client, resetSetConfigSql);
|
|
13862
|
-
sql.text = `RELEASE SAVEPOINT "t${transactionId}"`;
|
|
13863
|
-
if (log) ctx.logData = log.beforeQuery(sql);
|
|
13864
|
-
await transactionAdapter.arrays(sql.text, sql.values);
|
|
13865
|
-
if (log) log.afterQuery(sql, ctx.logData);
|
|
13863
|
+
const result = await transactionAdapter.savepoint(`t${transactionId}`, async () => {
|
|
13864
|
+
const setRoleSql = getSetRoleSql(parentRole, options);
|
|
13865
|
+
if (setRoleSql) driverAdapter.queryClient(client, setRoleSql);
|
|
13866
|
+
const setConfigSql = getSetConfigSql(parentSetConfig, options);
|
|
13867
|
+
if (setConfigSql) driverAdapter.queryClient(client, setConfigSql);
|
|
13868
|
+
let result;
|
|
13869
|
+
try {
|
|
13870
|
+
result = await cb(new TransactionAdapterClass(adapter, client));
|
|
13871
|
+
} finally {
|
|
13872
|
+
const resetRoleSql = getResetRoleSql(parentRole, options);
|
|
13873
|
+
if (resetRoleSql) await driverAdapter.queryClient(client, resetRoleSql);
|
|
13874
|
+
}
|
|
13875
|
+
const resetSetConfigSql = getResetSetConfigSql(parentSetConfig, options);
|
|
13876
|
+
if (resetSetConfigSql) driverAdapter.queryClient(client, resetSetConfigSql);
|
|
13877
|
+
return result;
|
|
13878
|
+
});
|
|
13866
13879
|
if (ctx.state && transactionId === ctx.state.testTransactionCount) {
|
|
13867
13880
|
const { afterCommit } = ctx.state;
|
|
13868
13881
|
ctx.state.afterCommit = void 0;
|
|
@@ -13913,19 +13926,19 @@ const runAfterCommit = (afterCommit, result) => {
|
|
|
13913
13926
|
}
|
|
13914
13927
|
});
|
|
13915
13928
|
};
|
|
13916
|
-
const runQueryHandlePool = async (pool, driverAdapter, text, values,
|
|
13929
|
+
const runQueryHandlePool = async (pool, driverAdapter, text, values, sqlSessionState, arraysMode, client) => {
|
|
13917
13930
|
const setup = sqlSessionContextComputeSetup(sqlSessionState);
|
|
13918
|
-
if (client || !driverAdapter.manualPool && !setup) return runQueryHandleSetupAndCleanup(driverAdapter, client || pool, text, values,
|
|
13931
|
+
if (client || !driverAdapter.manualPool && !setup) return runQueryHandleSetupAndCleanup(driverAdapter, client || pool, text, values, setup, arraysMode);
|
|
13919
13932
|
client = await driverAdapter.borrow(pool);
|
|
13920
13933
|
try {
|
|
13921
|
-
return await runQueryHandleSetupAndCleanup(driverAdapter, client, text, values,
|
|
13934
|
+
return await runQueryHandleSetupAndCleanup(driverAdapter, client, text, values, setup, arraysMode);
|
|
13922
13935
|
} finally {
|
|
13923
13936
|
driverAdapter.release(client);
|
|
13924
13937
|
}
|
|
13925
13938
|
};
|
|
13926
|
-
const runQueryHandleSetupAndCleanup = (driverAdapter, client, text, values,
|
|
13927
|
-
if (setup) return sqlSessionContextExecute((text, values) => driverAdapter.queryClient(client, text, values,
|
|
13928
|
-
return driverAdapter.queryClient(client, text, values,
|
|
13939
|
+
const runQueryHandleSetupAndCleanup = (driverAdapter, client, text, values, setup, arraysMode) => {
|
|
13940
|
+
if (setup) return sqlSessionContextExecute((text, values) => driverAdapter.queryClient(client, text, values, true), setup, () => driverAdapter.queryClient(client, text, values, arraysMode));
|
|
13941
|
+
return driverAdapter.queryClient(client, text, values, arraysMode);
|
|
13929
13942
|
};
|
|
13930
13943
|
const createAdapterConnectionState = (config) => {
|
|
13931
13944
|
const state = { originalConfig: { ...config } };
|