pqb 0.40.6 → 0.40.8
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 +123 -2
- package/dist/index.js +27 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3193,7 +3193,7 @@ const escape = (value, migration, nested) => {
|
|
|
3193
3193
|
else if (value instanceof Date)
|
|
3194
3194
|
return `'${value.toISOString()}'`;
|
|
3195
3195
|
else if (Array.isArray(value))
|
|
3196
|
-
return migration && nested && !value.length ? "" : (migration ? "{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? "}" : "]");
|
|
3196
|
+
return migration && nested && !value.length ? "" : (migration ? nested ? "{" : "'{" : nested ? "[" : "ARRAY[") + value.map((el) => escape(el, migration, true)).join(",") + (migration ? nested ? "}" : "}'" : "]");
|
|
3197
3197
|
else if (value === null || value === void 0)
|
|
3198
3198
|
return "NULL";
|
|
3199
3199
|
else
|
|
@@ -3395,6 +3395,32 @@ class Transaction {
|
|
|
3395
3395
|
}
|
|
3396
3396
|
}
|
|
3397
3397
|
}
|
|
3398
|
+
/**
|
|
3399
|
+
* Use the `$ensureTransaction` when you want to ensure the sequence of queries is running in a transaction, but there is no need for Postgres [savepoints](https://www.postgresql.org/docs/current/sql-savepoint.html).
|
|
3400
|
+
*
|
|
3401
|
+
* ```ts
|
|
3402
|
+
* async function updateUserBalance(userId: string, amount: number) {
|
|
3403
|
+
* await db.$ensureTransaction(async () => {
|
|
3404
|
+
* await db.transfer.create({ userId, amount })
|
|
3405
|
+
* await db.user.find(userId).increment({ balance: amount })
|
|
3406
|
+
* })
|
|
3407
|
+
* }
|
|
3408
|
+
*
|
|
3409
|
+
* async function saveDeposit(userId: string, deposit: { ... }) {
|
|
3410
|
+
* await db.$ensureTransaction(async () => {
|
|
3411
|
+
* await db.deposit.create(deposit)
|
|
3412
|
+
* // transaction in updateUserBalance won't be started
|
|
3413
|
+
* await updateUserBalance(userId, deposit.amount)
|
|
3414
|
+
* })
|
|
3415
|
+
* }
|
|
3416
|
+
* ```
|
|
3417
|
+
*/
|
|
3418
|
+
ensureTransaction(cb) {
|
|
3419
|
+
const trx = this.internal.transactionStorage.getStore();
|
|
3420
|
+
if (trx)
|
|
3421
|
+
return cb();
|
|
3422
|
+
return Transaction.prototype.transaction.call(this, cb);
|
|
3423
|
+
}
|
|
3398
3424
|
}
|
|
3399
3425
|
const runAfterCommit = async (afterCommit, result) => {
|
|
3400
3426
|
if (afterCommit) {
|