pqb 0.57.4 → 0.57.5
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 +7 -3
- package/dist/index.js +35 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -16
- package/dist/index.mjs.map +1 -1
- package/dist/node-postgres.d.ts +7 -6
- package/dist/node-postgres.js +73 -12
- package/dist/node-postgres.js.map +1 -1
- package/dist/node-postgres.mjs +73 -12
- package/dist/node-postgres.mjs.map +1 -1
- package/dist/postgres-js.d.ts +7 -6
- package/dist/postgres-js.js +44 -16
- package/dist/postgres-js.js.map +1 -1
- package/dist/postgres-js.mjs +44 -16
- package/dist/postgres-js.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1738,8 +1738,8 @@ interface AdapterBase {
|
|
|
1738
1738
|
getSchema(): string | undefined;
|
|
1739
1739
|
getHost(): string;
|
|
1740
1740
|
connect?(): Promise<unknown>;
|
|
1741
|
-
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[]): Promise<QueryResult<T>>;
|
|
1742
|
-
arrays<R extends any[] = any[]>(text: string, values?: unknown[]): Promise<QueryArraysResult<R>>;
|
|
1741
|
+
query<T extends QueryResultRow = QueryResultRow>(text: string, values?: unknown[], catchingSavepoint?: string): Promise<QueryResult<T>>;
|
|
1742
|
+
arrays<R extends any[] = any[]>(text: string, values?: unknown[], catchingSavepoint?: string): Promise<QueryArraysResult<R>>;
|
|
1743
1743
|
/**
|
|
1744
1744
|
* Run a transaction
|
|
1745
1745
|
*
|
|
@@ -1755,6 +1755,7 @@ interface TransactionState {
|
|
|
1755
1755
|
afterCommit?: TransactionAfterCommitHook[];
|
|
1756
1756
|
log?: QueryLogObject;
|
|
1757
1757
|
testTransactionCount?: number;
|
|
1758
|
+
catchI?: number;
|
|
1758
1759
|
}
|
|
1759
1760
|
/**
|
|
1760
1761
|
* Element of `afterCommit` transaction array. See {@link TransactionState.afterCommit}.
|
|
@@ -2078,6 +2079,7 @@ interface QueryData extends QueryDataBase {
|
|
|
2078
2079
|
shape: ColumnsShape;
|
|
2079
2080
|
patchResult?(q: Query, hookSelect: HookSelect | undefined, queryResult: QueryResult): Promise<void>;
|
|
2080
2081
|
handleResult: HandleResult;
|
|
2082
|
+
catch?: boolean;
|
|
2081
2083
|
returnType: QueryReturnType;
|
|
2082
2084
|
returning?: boolean;
|
|
2083
2085
|
returningMany?: boolean;
|
|
@@ -7349,7 +7351,9 @@ declare const queryMethodByReturnType: {
|
|
|
7349
7351
|
[K in string]: 'query' | 'arrays';
|
|
7350
7352
|
};
|
|
7351
7353
|
interface QueryCatchers {
|
|
7352
|
-
catchUniqueError<
|
|
7354
|
+
catchUniqueError<ThenResult, CatchResult>(this: {
|
|
7355
|
+
then: (onfulfilled?: (value: ThenResult) => any) => any;
|
|
7356
|
+
}, fn: (reason: QueryError) => CatchResult): Promise<ThenResult | CatchResult>;
|
|
7353
7357
|
}
|
|
7354
7358
|
declare class Then implements QueryCatchers {
|
|
7355
7359
|
catch(this: Query, fn: (reason: any) => unknown): Promise<unknown>;
|
package/dist/index.js
CHANGED
|
@@ -3620,11 +3620,11 @@ const isQueryReturnsAll = (q) => !q.q.returnType || q.q.returnType === "all";
|
|
|
3620
3620
|
function simpleColumnToSQL(ctx, key, column, quotedAs) {
|
|
3621
3621
|
if (!column) return `"${key}"`;
|
|
3622
3622
|
const { data } = column;
|
|
3623
|
-
return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
3623
|
+
return data.computed ? `(${data.computed.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
3624
3624
|
}
|
|
3625
3625
|
function simpleExistingColumnToSQL(ctx, key, column, quotedAs) {
|
|
3626
3626
|
const { data } = column;
|
|
3627
|
-
return data.computed ? data.computed.toSQL(ctx, quotedAs) : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
3627
|
+
return data.computed ? `(${data.computed.toSQL(ctx, quotedAs)})` : `${quotedAs ? `${quotedAs}.` : ""}"${data.name || key}"`;
|
|
3628
3628
|
}
|
|
3629
3629
|
const columnToSql = (ctx, data, shape, column, quotedAs, select) => {
|
|
3630
3630
|
const index = column.indexOf(".");
|
|
@@ -3679,7 +3679,7 @@ const columnWithDotToSql = (ctx, data, shape, column, index, quotedAs, select) =
|
|
|
3679
3679
|
return `"${tableName}"."${col.data.name}"`;
|
|
3680
3680
|
}
|
|
3681
3681
|
if (col.data.computed) {
|
|
3682
|
-
return col.data.computed.toSQL(ctx, quoted)
|
|
3682
|
+
return `(${col.data.computed.toSQL(ctx, quoted)})`;
|
|
3683
3683
|
}
|
|
3684
3684
|
return `"${tableName}"."${key}"`;
|
|
3685
3685
|
}
|
|
@@ -3719,7 +3719,7 @@ const tableColumnToSqlWithAs = (ctx, data, column, table, key, as, quotedAs, sel
|
|
|
3719
3719
|
return `"${tableName}"."${col.data.name}" "${as}"`;
|
|
3720
3720
|
}
|
|
3721
3721
|
if (col.data.computed) {
|
|
3722
|
-
return
|
|
3722
|
+
return `(${col.data.computed.toSQL(ctx, quoted)}) "${as}"`;
|
|
3723
3723
|
}
|
|
3724
3724
|
}
|
|
3725
3725
|
return `"${tableName}"."${key}"${key === as ? "" : ` "${as}"`}`;
|
|
@@ -3732,7 +3732,7 @@ const ownColumnToSqlWithAs = (ctx, data, column, as, quotedAs, select, jsonList)
|
|
|
3732
3732
|
return `${quotedAs ? `${quotedAs}.` : ""}"${col.data.name}"${col.data.name === as ? "" : ` "${as}"`}`;
|
|
3733
3733
|
}
|
|
3734
3734
|
if (col.data.computed) {
|
|
3735
|
-
return
|
|
3735
|
+
return `(${col.data.computed.toSQL(ctx, quotedAs)}) "${as}"`;
|
|
3736
3736
|
}
|
|
3737
3737
|
}
|
|
3738
3738
|
return `${quotedAs ? `${quotedAs}.` : ""}"${column}"${column === as ? "" : ` "${as}"`}`;
|
|
@@ -4247,7 +4247,8 @@ const skipQueryKeysForSubQuery = {
|
|
|
4247
4247
|
catchAfterCommitErrors: true,
|
|
4248
4248
|
log: true,
|
|
4249
4249
|
logger: true,
|
|
4250
|
-
autoPreparedStatements: true
|
|
4250
|
+
autoPreparedStatements: true,
|
|
4251
|
+
catch: true
|
|
4251
4252
|
};
|
|
4252
4253
|
const getIsJoinSubQuery = (query) => {
|
|
4253
4254
|
const {
|
|
@@ -6169,12 +6170,16 @@ const queryMethodByReturnType = {
|
|
|
6169
6170
|
class Then {
|
|
6170
6171
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
6171
6172
|
catch(fn) {
|
|
6172
|
-
|
|
6173
|
+
const q = _clone(this);
|
|
6174
|
+
q.q.catch = true;
|
|
6175
|
+
return q.then(void 0, fn);
|
|
6173
6176
|
}
|
|
6174
6177
|
catchUniqueError(fn) {
|
|
6175
|
-
|
|
6178
|
+
const q = _clone(this);
|
|
6179
|
+
q.q.catch = true;
|
|
6180
|
+
return q.then(void 0, (err) => {
|
|
6176
6181
|
if (err instanceof QueryError && err.isUnique) {
|
|
6177
|
-
fn(err);
|
|
6182
|
+
return fn(err);
|
|
6178
6183
|
} else {
|
|
6179
6184
|
throw err;
|
|
6180
6185
|
}
|
|
@@ -6197,6 +6202,7 @@ Object.defineProperty(Then.prototype, "then", {
|
|
|
6197
6202
|
});
|
|
6198
6203
|
function maybeWrappedThen(resolve, reject) {
|
|
6199
6204
|
const { q } = this;
|
|
6205
|
+
const shouldCatch = q.catch || !!reject;
|
|
6200
6206
|
let beforeHooks;
|
|
6201
6207
|
let afterHooks;
|
|
6202
6208
|
let afterCommitHooks;
|
|
@@ -6228,7 +6234,8 @@ function maybeWrappedThen(resolve, reject) {
|
|
|
6228
6234
|
afterHooks,
|
|
6229
6235
|
afterCommitHooks,
|
|
6230
6236
|
resolve2,
|
|
6231
|
-
reject2
|
|
6237
|
+
reject2,
|
|
6238
|
+
shouldCatch
|
|
6232
6239
|
);
|
|
6233
6240
|
})
|
|
6234
6241
|
).then(resolve, reject);
|
|
@@ -6241,7 +6248,8 @@ function maybeWrappedThen(resolve, reject) {
|
|
|
6241
6248
|
afterHooks,
|
|
6242
6249
|
afterCommitHooks,
|
|
6243
6250
|
resolve,
|
|
6244
|
-
reject
|
|
6251
|
+
reject,
|
|
6252
|
+
shouldCatch
|
|
6245
6253
|
);
|
|
6246
6254
|
}
|
|
6247
6255
|
}
|
|
@@ -6251,7 +6259,7 @@ const callAfterHook = function(cb) {
|
|
|
6251
6259
|
return cb(this[0], this[1]);
|
|
6252
6260
|
};
|
|
6253
6261
|
const beginSql = { text: "BEGIN" };
|
|
6254
|
-
const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks, resolve, reject) => {
|
|
6262
|
+
const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks, resolve, reject, shouldCatch) => {
|
|
6255
6263
|
var _a;
|
|
6256
6264
|
const { q: query } = q;
|
|
6257
6265
|
let sql;
|
|
@@ -6284,7 +6292,8 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
6284
6292
|
queryResult = await execQuery(
|
|
6285
6293
|
adapter,
|
|
6286
6294
|
queryMethodByReturnType[tempReturnType],
|
|
6287
|
-
sql
|
|
6295
|
+
sql,
|
|
6296
|
+
shouldCatch && trx
|
|
6288
6297
|
);
|
|
6289
6298
|
if (log) {
|
|
6290
6299
|
log.afterQuery(sql, logData);
|
|
@@ -6314,7 +6323,12 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
6314
6323
|
if (log) {
|
|
6315
6324
|
logData = log.beforeQuery(sql);
|
|
6316
6325
|
}
|
|
6317
|
-
const result2 = await execQuery(
|
|
6326
|
+
const result2 = await execQuery(
|
|
6327
|
+
adapter,
|
|
6328
|
+
queryMethod,
|
|
6329
|
+
sql,
|
|
6330
|
+
shouldCatch && trx
|
|
6331
|
+
);
|
|
6318
6332
|
if (queryResult) {
|
|
6319
6333
|
queryResult.rowCount += result2.rowCount;
|
|
6320
6334
|
queryResult.rows.push(...result2.rows);
|
|
@@ -6586,8 +6600,13 @@ const then = async (q, adapter, trx, beforeHooks, afterHooks, afterCommitHooks,
|
|
|
6586
6600
|
throw error;
|
|
6587
6601
|
}
|
|
6588
6602
|
};
|
|
6589
|
-
const execQuery = (adapter, method, sql) => {
|
|
6590
|
-
|
|
6603
|
+
const execQuery = (adapter, method, sql, catchTrx) => {
|
|
6604
|
+
const catchingSavepoint = catchTrx ? String(catchTrx.catchI = (catchTrx.catchI || 0) + 1) : void 0;
|
|
6605
|
+
return adapter[method](
|
|
6606
|
+
sql.text,
|
|
6607
|
+
sql.values,
|
|
6608
|
+
catchingSavepoint
|
|
6609
|
+
).then((result) => {
|
|
6591
6610
|
if (result.rowCount && !result.rows.length) {
|
|
6592
6611
|
result.rows.length = result.rowCount;
|
|
6593
6612
|
result.rows.fill({});
|