linkgress-orm 0.4.33 → 0.4.34
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/database/database-client.interface.d.ts +33 -0
- package/dist/database/database-client.interface.d.ts.map +1 -1
- package/dist/database/database-client.interface.js +21 -1
- package/dist/database/database-client.interface.js.map +1 -1
- package/dist/database/index.d.ts +2 -1
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +2 -1
- package/dist/database/index.js.map +1 -1
- package/dist/database/postgres-client.d.ts +11 -0
- package/dist/database/postgres-client.d.ts.map +1 -1
- package/dist/database/postgres-client.js +89 -15
- package/dist/database/postgres-client.js.map +1 -1
- package/dist/database/types.d.ts +12 -0
- package/dist/database/types.d.ts.map +1 -1
- package/dist/entity/db-context.d.ts +197 -6
- package/dist/entity/db-context.d.ts.map +1 -1
- package/dist/entity/db-context.js +310 -53
- package/dist/entity/db-context.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/query/grouped-query.d.ts +38 -1
- package/dist/query/grouped-query.d.ts.map +1 -1
- package/dist/query/grouped-query.js +67 -0
- package/dist/query/grouped-query.js.map +1 -1
- package/dist/query/join-builder.d.ts +14 -1
- package/dist/query/join-builder.d.ts.map +1 -1
- package/dist/query/join-builder.js +23 -0
- package/dist/query/join-builder.js.map +1 -1
- package/dist/query/query-builder.d.ts +33 -1
- package/dist/query/query-builder.d.ts.map +1 -1
- package/dist/query/query-builder.js +51 -0
- package/dist/query/query-builder.js.map +1 -1
- package/dist/query/union-builder.d.ts +14 -1
- package/dist/query/union-builder.d.ts.map +1 -1
- package/dist/query/union-builder.js +23 -0
- package/dist/query/union-builder.js.map +1 -1
- package/package.json +1 -1
|
@@ -15,6 +15,39 @@ export interface QueryExecutionOptions {
|
|
|
15
15
|
* Default: false (uses text protocol)
|
|
16
16
|
*/
|
|
17
17
|
useBinaryProtocol?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Per-query timeout override, in milliseconds. Set by `.withTimeout(ms)`.
|
|
20
|
+
*
|
|
21
|
+
* When present, the driver runs *this query only* inside a short transaction
|
|
22
|
+
* that issues `SET LOCAL statement_timeout` first — so the override is scoped
|
|
23
|
+
* to the query (auto-resets at COMMIT) and cannot affect other queries on the
|
|
24
|
+
* pooled connection. A value of `0` disables the timeout for this query
|
|
25
|
+
* (overriding any connection-level default). When absent, no wrapping happens
|
|
26
|
+
* and the connection-level default (if any) applies.
|
|
27
|
+
*
|
|
28
|
+
* On timeout the driver throws a {@link QueryTimeoutError}.
|
|
29
|
+
*
|
|
30
|
+
* NOTE: Currently only honored by `PostgresClient` (the `postgres`/porsager
|
|
31
|
+
* driver). `PgClient` and `BunClient` ignore it.
|
|
32
|
+
*/
|
|
33
|
+
timeoutMs?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Error thrown when a query is cancelled because it exceeded its timeout — the
|
|
37
|
+
* per-query `.withTimeout(ms)` override or the connection-level
|
|
38
|
+
* `statement_timeout` default.
|
|
39
|
+
*
|
|
40
|
+
* The underlying database error (PostgreSQL code `57014`, "canceling statement
|
|
41
|
+
* due to statement timeout") is preserved on the `cause` property.
|
|
42
|
+
*/
|
|
43
|
+
export declare class QueryTimeoutError extends Error {
|
|
44
|
+
/** The timeout that was exceeded, in milliseconds (`0` if not known). */
|
|
45
|
+
readonly timeoutMs: number;
|
|
46
|
+
/** The SQL text of the query that timed out. */
|
|
47
|
+
readonly sql: string;
|
|
48
|
+
/** The original driver error that surfaced the cancellation, if any. */
|
|
49
|
+
readonly cause?: unknown;
|
|
50
|
+
constructor(timeoutMs: number, sql: string, cause?: unknown);
|
|
18
51
|
}
|
|
19
52
|
/**
|
|
20
53
|
* Database-agnostic pooled client/connection interface
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-client.interface.d.ts","sourceRoot":"","sources":["../../src/database/database-client.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"database-client.interface.d.ts","sourceRoot":"","sources":["../../src/database/database-client.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAClC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,gDAAgD;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,wEAAwE;IACxE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;gBAEb,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAS5D;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACtG,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;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OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAKpC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IAI1B,aAAa,IAAI,MAAM;IAIjB,WAAW,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,WAAW,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAKzH,6BAA6B,IAAI,OAAO;IAIxC,sBAAsB,IAAI,OAAO;CAGlC"}
|
|
@@ -1,6 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransactionalClient = exports.DatabaseClient = void 0;
|
|
3
|
+
exports.TransactionalClient = exports.DatabaseClient = exports.QueryTimeoutError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Error thrown when a query is cancelled because it exceeded its timeout — the
|
|
6
|
+
* per-query `.withTimeout(ms)` override or the connection-level
|
|
7
|
+
* `statement_timeout` default.
|
|
8
|
+
*
|
|
9
|
+
* The underlying database error (PostgreSQL code `57014`, "canceling statement
|
|
10
|
+
* due to statement timeout") is preserved on the `cause` property.
|
|
11
|
+
*/
|
|
12
|
+
class QueryTimeoutError extends Error {
|
|
13
|
+
constructor(timeoutMs, sql, cause) {
|
|
14
|
+
super(`Query exceeded its timeout of ${timeoutMs}ms and was cancelled`);
|
|
15
|
+
this.name = 'QueryTimeoutError';
|
|
16
|
+
this.timeoutMs = timeoutMs;
|
|
17
|
+
this.sql = sql;
|
|
18
|
+
this.cause = cause;
|
|
19
|
+
// Restore prototype chain so `instanceof` works when targeting ES5
|
|
20
|
+
Object.setPrototypeOf(this, QueryTimeoutError.prototype);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.QueryTimeoutError = QueryTimeoutError;
|
|
4
24
|
/**
|
|
5
25
|
* Base database client interface that all drivers must implement
|
|
6
26
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"database-client.interface.js","sourceRoot":"","sources":["../../src/database/database-client.interface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"database-client.interface.js","sourceRoot":"","sources":["../../src/database/database-client.interface.ts"],"names":[],"mappings":";;;AAqCA;;;;;;;GAOG;AACH,MAAa,iBAAkB,SAAQ,KAAK;IAQ1C,YAAY,SAAiB,EAAE,GAAW,EAAE,KAAe;QACzD,KAAK,CAAC,iCAAiC,SAAS,sBAAsB,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,mEAAmE;QACnE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAjBD,8CAiBC;AAWD;;GAEG;AACH,MAAsB,cAAc;IAClC;;OAEG;IACH,eAAe;QACb,OAAO,KAAK,CAAC;IACf,CAAC;IA8BD;;;;;;OAMG;IACH,6BAA6B;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,sBAAsB;QACpB,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAtDD,wCAsDC;AAED;;;GAGG;AACH,MAAa,mBAAoB,SAAQ,cAAc;IACrD,YACU,OAA8D,EAC9D,YAA4B;QAEpC,KAAK,EAAE,CAAC;QAHA,YAAO,GAAP,OAAO,CAAuD;QAC9D,iBAAY,GAAZ,YAAY,CAAgB;IAGtC,CAAC;IAED,eAAe;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAAK,CAAU,GAAW,EAAE,MAAc,EAAE,QAAgC;QAChF,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAmB,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,OAAO;QACX,gEAAgE;QAChE,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IAED,KAAK,CAAC,GAAG;QACP,6DAA6D;IAC/D,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,WAAW,CAAI,SAAuF;QAC1G,+EAA+E;QAC/E,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,6BAA6B;QAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,6BAA6B,EAAE,CAAC;IAC3D,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,sBAAsB,EAAE,CAAC;IACpD,CAAC;CACF;AAzCD,kDAyCC"}
|
package/dist/database/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { DatabaseClient, PooledConnection, QueryResult } from './database-client.interface';
|
|
1
|
+
export { DatabaseClient, PooledConnection, QueryResult, QueryTimeoutError } from './database-client.interface';
|
|
2
|
+
export type { QueryExecutionOptions } from './database-client.interface';
|
|
2
3
|
export { PostgresClient } from './postgres-client';
|
|
3
4
|
export { PgClient } from './pg-client';
|
|
4
5
|
export type { PoolConfig, PostgresOptions } from './types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAC/G,YAAY,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/database/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PgClient = exports.PostgresClient = exports.DatabaseClient = void 0;
|
|
3
|
+
exports.PgClient = exports.PostgresClient = exports.QueryTimeoutError = exports.DatabaseClient = void 0;
|
|
4
4
|
var database_client_interface_1 = require("./database-client.interface");
|
|
5
5
|
Object.defineProperty(exports, "DatabaseClient", { enumerable: true, get: function () { return database_client_interface_1.DatabaseClient; } });
|
|
6
|
+
Object.defineProperty(exports, "QueryTimeoutError", { enumerable: true, get: function () { return database_client_interface_1.QueryTimeoutError; } });
|
|
6
7
|
var postgres_client_1 = require("./postgres-client");
|
|
7
8
|
Object.defineProperty(exports, "PostgresClient", { enumerable: true, get: function () { return postgres_client_1.PostgresClient; } });
|
|
8
9
|
var pg_client_1 = require("./pg-client");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/database/index.ts"],"names":[],"mappings":";;;AAAA,yEAA+G;AAAtG,2HAAA,cAAc,OAAA;AAAiC,8HAAA,iBAAiB,OAAA;AAEzE,qDAAmD;AAA1C,iHAAA,cAAc,OAAA;AACvB,yCAAuC;AAA9B,qGAAA,QAAQ,OAAA"}
|
|
@@ -11,11 +11,22 @@ type Sql = any;
|
|
|
11
11
|
export declare class PostgresClient extends DatabaseClient {
|
|
12
12
|
private sql;
|
|
13
13
|
private ownsConnection;
|
|
14
|
+
/** Default statement_timeout (ms) configured at construction, if any. */
|
|
15
|
+
private defaultStatementTimeout?;
|
|
14
16
|
/**
|
|
15
17
|
* Create a PostgresClient
|
|
16
18
|
* @param config - Either a connection string, PostgresOptions config object, or an existing postgres.Sql instance
|
|
17
19
|
*/
|
|
18
20
|
constructor(config: string | PostgresOptions | Sql);
|
|
21
|
+
/**
|
|
22
|
+
* Move a top-level `statement_timeout` (ms) option onto the porsager
|
|
23
|
+
* `connection` parameters so PostgreSQL applies it as a native, connection-level
|
|
24
|
+
* default (server-enforced, no per-query wrapping). Other config is untouched.
|
|
25
|
+
*
|
|
26
|
+
* String/URL configs are passed through unchanged — for those, set the default
|
|
27
|
+
* via the connection string or use a config object.
|
|
28
|
+
*/
|
|
29
|
+
private normalizeConfig;
|
|
19
30
|
query<T = any>(sql: string, params?: any[], options?: QueryExecutionOptions): Promise<QueryResult<T>>;
|
|
20
31
|
connect(): Promise<PooledConnection>;
|
|
21
32
|
end(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-client.d.ts","sourceRoot":"","sources":["../../src/database/postgres-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"postgres-client.d.ts","sourceRoot":"","sources":["../../src/database/postgres-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,WAAW,EAAE,qBAAqB,EAAqB,MAAM,6BAA6B,CAAC;AACtI,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,KAAK,GAAG,GAAG,GAAG,CAAC;AAwFf;;;;;;GAMG;AACH,qBAAa,cAAe,SAAQ,cAAc;IAChD,OAAO,CAAC,GAAG,CAAM;IACjB,OAAO,CAAC,cAAc,CAAU;IAChC,yEAAyE;IACzE,OAAO,CAAC,uBAAuB,CA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client_interface_1 = require("./database-client.interface");
|
|
5
|
+
/** PostgreSQL error code raised when a statement is cancelled due to a timeout. */
|
|
6
|
+
const STATEMENT_TIMEOUT_CODE = '57014';
|
|
5
7
|
/**
|
|
6
8
|
* Check if a value is a postgres.Sql instance
|
|
7
9
|
*/
|
|
8
10
|
function isPostgresSqlInstance(value) {
|
|
9
11
|
return value && typeof value === 'function' && typeof value.unsafe === 'function' && typeof value.end === 'function';
|
|
10
12
|
}
|
|
13
|
+
/** Clamp a timeout to a safe non-negative integer for inlining into SET LOCAL. */
|
|
14
|
+
function normalizeTimeoutMs(timeoutMs) {
|
|
15
|
+
return Number.isFinite(timeoutMs) ? Math.max(0, Math.floor(timeoutMs)) : 0;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Translate a statement-timeout cancellation (PostgreSQL `57014`) into a typed
|
|
19
|
+
* {@link QueryTimeoutError}. Any other error is returned unchanged.
|
|
20
|
+
*/
|
|
21
|
+
function asTimeoutError(error, timeoutMs, sql) {
|
|
22
|
+
if (error && error.code === STATEMENT_TIMEOUT_CODE) {
|
|
23
|
+
return new database_client_interface_1.QueryTimeoutError(timeoutMs ?? 0, sql, error);
|
|
24
|
+
}
|
|
25
|
+
return error;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Execute a single statement against a `postgres` (porsager) sql instance,
|
|
29
|
+
* honoring an optional per-query timeout override.
|
|
30
|
+
*
|
|
31
|
+
* - No override (`timeoutMs === undefined`): run the query directly. Any
|
|
32
|
+
* connection-level `statement_timeout` default still applies (server-enforced,
|
|
33
|
+
* no wrapping).
|
|
34
|
+
* - Override present: run the query inside a short transaction that issues
|
|
35
|
+
* `SET LOCAL statement_timeout` first. `SET LOCAL` is scoped to the
|
|
36
|
+
* transaction and auto-resets at COMMIT, so it never leaks to other queries on
|
|
37
|
+
* the pooled connection. `timeoutMs === 0` disables the timeout for this query.
|
|
38
|
+
*
|
|
39
|
+
* A statement-timeout cancellation is surfaced as a {@link QueryTimeoutError}.
|
|
40
|
+
*/
|
|
41
|
+
async function runStatement(sqlInstance, sql, params, timeoutMs, defaultTimeoutMs) {
|
|
42
|
+
if (timeoutMs === undefined) {
|
|
43
|
+
try {
|
|
44
|
+
const result = await sqlInstance.unsafe(sql, params || []);
|
|
45
|
+
return { rows: result, rowCount: result.count ?? null };
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw asTimeoutError(error, defaultTimeoutMs, sql);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Per-query override: wrap only this query so SET LOCAL auto-resets at COMMIT.
|
|
52
|
+
try {
|
|
53
|
+
return await sqlInstance.begin(async (tx) => {
|
|
54
|
+
await tx.unsafe(`SET LOCAL statement_timeout = ${normalizeTimeoutMs(timeoutMs)}`);
|
|
55
|
+
const result = await tx.unsafe(sql, params || []);
|
|
56
|
+
return { rows: result, rowCount: result.count ?? null };
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
throw asTimeoutError(error, timeoutMs, sql);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
11
63
|
/**
|
|
12
64
|
* Wrapper for the pooled connection from postgres library
|
|
13
65
|
*/
|
|
14
66
|
class PostgresPooledConnection {
|
|
15
|
-
constructor(sql) {
|
|
67
|
+
constructor(sql, defaultStatementTimeout) {
|
|
16
68
|
this.sql = sql;
|
|
69
|
+
this.defaultStatementTimeout = defaultStatementTimeout;
|
|
17
70
|
}
|
|
18
71
|
async query(sql, params, options) {
|
|
19
72
|
// postgres library doesn't have explicit binary protocol toggle
|
|
20
|
-
// It automatically uses the most efficient protocol based on data types
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
rows: result,
|
|
24
|
-
rowCount: result.count ?? null,
|
|
25
|
-
};
|
|
73
|
+
// It automatically uses the most efficient protocol based on data types.
|
|
74
|
+
return await runStatement(this.sql, sql, params, options?.timeoutMs, this.defaultStatementTimeout);
|
|
26
75
|
}
|
|
27
76
|
release() {
|
|
28
77
|
// postgres library handles connection pooling automatically
|
|
@@ -52,7 +101,7 @@ class PostgresClient extends database_client_interface_1.DatabaseClient {
|
|
|
52
101
|
try {
|
|
53
102
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
54
103
|
const postgres = require('postgres');
|
|
55
|
-
this.sql = postgres(config);
|
|
104
|
+
this.sql = postgres(this.normalizeConfig(config));
|
|
56
105
|
this.ownsConnection = true;
|
|
57
106
|
}
|
|
58
107
|
catch (error) {
|
|
@@ -61,20 +110,45 @@ class PostgresClient extends database_client_interface_1.DatabaseClient {
|
|
|
61
110
|
}
|
|
62
111
|
}
|
|
63
112
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
113
|
+
/**
|
|
114
|
+
* Move a top-level `statement_timeout` (ms) option onto the porsager
|
|
115
|
+
* `connection` parameters so PostgreSQL applies it as a native, connection-level
|
|
116
|
+
* default (server-enforced, no per-query wrapping). Other config is untouched.
|
|
117
|
+
*
|
|
118
|
+
* String/URL configs are passed through unchanged — for those, set the default
|
|
119
|
+
* via the connection string or use a config object.
|
|
120
|
+
*/
|
|
121
|
+
normalizeConfig(config) {
|
|
122
|
+
if (typeof config !== 'object' || config === null) {
|
|
123
|
+
return config;
|
|
124
|
+
}
|
|
125
|
+
const options = config;
|
|
126
|
+
const statementTimeout = options.statement_timeout;
|
|
127
|
+
if (statementTimeout === undefined) {
|
|
128
|
+
return config;
|
|
129
|
+
}
|
|
130
|
+
this.defaultStatementTimeout = statementTimeout;
|
|
131
|
+
// Clone, drop the top-level alias, and push it into the connection params
|
|
132
|
+
// (porsager sends `connection.*` as PostgreSQL connection parameters).
|
|
133
|
+
const { statement_timeout: _omit, connection, ...rest } = options;
|
|
68
134
|
return {
|
|
69
|
-
|
|
70
|
-
|
|
135
|
+
...rest,
|
|
136
|
+
connection: {
|
|
137
|
+
...(connection || {}),
|
|
138
|
+
statement_timeout: normalizeTimeoutMs(statementTimeout),
|
|
139
|
+
},
|
|
71
140
|
};
|
|
72
141
|
}
|
|
142
|
+
async query(sql, params, options) {
|
|
143
|
+
// postgres library doesn't have explicit binary protocol toggle
|
|
144
|
+
// It automatically uses the most efficient protocol based on data types.
|
|
145
|
+
return await runStatement(this.sql, sql, params, options?.timeoutMs, this.defaultStatementTimeout);
|
|
146
|
+
}
|
|
73
147
|
async connect() {
|
|
74
148
|
// postgres library doesn't expose individual connections in the same way
|
|
75
149
|
// We'll return a wrapper that uses the same sql instance
|
|
76
150
|
// For transactions, the library handles it through sql.begin()
|
|
77
|
-
return new PostgresPooledConnection(this.sql);
|
|
151
|
+
return new PostgresPooledConnection(this.sql, this.defaultStatementTimeout);
|
|
78
152
|
}
|
|
79
153
|
async end() {
|
|
80
154
|
// Only close the connection if we created it
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-client.js","sourceRoot":"","sources":["../../src/database/postgres-client.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"postgres-client.js","sourceRoot":"","sources":["../../src/database/postgres-client.ts"],"names":[],"mappings":";;;AAAA,2EAAsI;AAMtI,mFAAmF;AACnF,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACH,SAAS,qBAAqB,CAAC,KAAU;IACvC,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,IAAI,OAAO,KAAK,CAAC,GAAG,KAAK,UAAU,CAAC;AACvH,CAAC;AAED,kFAAkF;AAClF,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,OAAO,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,KAAU,EAAE,SA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AAI,EAAE,MAAe;oBACrB,QAAQ,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI;iBAC/B,CAAC;YACJ,CAAC,CAAC;YAEF,OAAO,MAAM,QAAQ,CAAC,OAAO,CAAC,CAAC;QACjC,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,sBAAsB;QACpB,OAAO,KAAK,CAAC,CAAC,kDAAkD;IAClE,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;CACF;AAzKD,wCAyKC"}
|
package/dist/database/types.d.ts
CHANGED
|
@@ -140,6 +140,18 @@ export interface PostgresOptions {
|
|
|
140
140
|
* Timeout for queries in seconds (default: undefined)
|
|
141
141
|
*/
|
|
142
142
|
timeout?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Default PostgreSQL `statement_timeout` in **milliseconds**, applied to every
|
|
145
|
+
* query on this client (default: undefined — no timeout).
|
|
146
|
+
*
|
|
147
|
+
* This is set as a native connection-level parameter, so it is enforced by the
|
|
148
|
+
* server with zero per-query overhead and no query wrapping. When a query
|
|
149
|
+
* exceeds it the server cancels it and the driver throws a `QueryTimeoutError`.
|
|
150
|
+
*
|
|
151
|
+
* Override (or disable) it for an individual query with `.withTimeout(ms)`
|
|
152
|
+
* (`.withTimeout(0)` disables the timeout for that one query).
|
|
153
|
+
*/
|
|
154
|
+
statement_timeout?: number;
|
|
143
155
|
/**
|
|
144
156
|
* SSL configuration (default: false)
|
|
145
157
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/database/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,C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,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;CACjC"}
|
|
@@ -75,17 +75,40 @@ export type OrderByTuple<T = unknown> = [T, OrderDirection];
|
|
|
75
75
|
*/
|
|
76
76
|
export type OrderByResult<T = unknown> = T | T[] | Array<OrderByTuple<T>>;
|
|
77
77
|
/**
|
|
78
|
-
*
|
|
78
|
+
* The section a log message belongs to — *what* is being logged — so a custom
|
|
79
|
+
* logger can route or filter by category (e.g. drop `'sql'`, keep `'error'`).
|
|
80
|
+
*
|
|
81
|
+
* - `'sql'` — the SQL query text
|
|
82
|
+
* - `'params'` — query parameters
|
|
83
|
+
* - `'timing'` — execution time / time-trace output
|
|
84
|
+
* - `'slow'` — a slow-query notice (see `onQueryTakingTooLong`)
|
|
85
|
+
* - `'info'` — general informational messages (migrations, etc.)
|
|
86
|
+
* - `'warn'` — warnings
|
|
87
|
+
* - `'error'` — errors
|
|
88
|
+
*/
|
|
89
|
+
export type LogSection = 'sql' | 'params' | 'timing' | 'slow' | 'info' | 'warn' | 'error';
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Renamed to {@link LogSection}. The logger's second argument is now
|
|
92
|
+
* the log *section* (what is being logged), not a severity level. Kept as an alias.
|
|
93
|
+
*/
|
|
94
|
+
export type LogLevel = LogSection;
|
|
95
|
+
/**
|
|
96
|
+
* Default logger used when no custom `logger` is provided. Routes by section to
|
|
97
|
+
* the appropriate console method.
|
|
79
98
|
*/
|
|
80
|
-
export
|
|
99
|
+
export declare function defaultLogger(message: string, section?: LogSection): void;
|
|
81
100
|
/**
|
|
82
101
|
* Query execution options
|
|
83
102
|
*/
|
|
84
103
|
export interface QueryOptions {
|
|
85
104
|
/** Enable SQL query logging */
|
|
86
105
|
logQueries?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Custom logger function (defaults to {@link defaultLogger}). The second
|
|
108
|
+
* argument is the {@link LogSection} — what is being logged ('sql', 'params',
|
|
109
|
+
* 'timing', 'error', ...) — so the logger can filter or route by category.
|
|
110
|
+
*/
|
|
111
|
+
logger?: (message: string, section?: LogSection) => void;
|
|
89
112
|
/** Log query execution time */
|
|
90
113
|
logExecutionTime?: boolean;
|
|
91
114
|
/** Log query parameters */
|
|
@@ -124,6 +147,49 @@ export interface QueryOptions {
|
|
|
124
147
|
* Default: false
|
|
125
148
|
*/
|
|
126
149
|
traceTime?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Callback invoked when a query's execution time exceeds its expected
|
|
152
|
+
* threshold (the default {@link longRunningQueryThreshold}, or a per-query
|
|
153
|
+
* `.expectedExecutionTime(ms)` override). Providing this callback enables
|
|
154
|
+
* slow-query detection — which captures a call stack per query, so leave it
|
|
155
|
+
* unset when you don't need it.
|
|
156
|
+
*
|
|
157
|
+
* The query still runs to completion (this is a diagnostic notice, not a
|
|
158
|
+
* cancellation — use `.withTimeout()` to actually cancel). The callback
|
|
159
|
+
* receives the SQL, params, duration, threshold, and the **user** call stack
|
|
160
|
+
* that initiated the query (internal linkgress frames removed), so the top
|
|
161
|
+
* frame is the code that called `.toList()` / `.firstOrDefault()` / etc.
|
|
162
|
+
*
|
|
163
|
+
* Errors thrown by the callback are swallowed so they cannot affect the query.
|
|
164
|
+
*/
|
|
165
|
+
onQueryTakingTooLong?: (info: SlowQueryInfo) => void;
|
|
166
|
+
/**
|
|
167
|
+
* Threshold in milliseconds above which a query is considered "too long" and
|
|
168
|
+
* {@link onQueryTakingTooLong} fires. Overridable per query with
|
|
169
|
+
* `.expectedExecutionTime(ms)`. Default: 10000 (10s).
|
|
170
|
+
*/
|
|
171
|
+
longRunningQueryThreshold?: number;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Details passed to the {@link QueryOptions.onQueryTakingTooLong} callback when a
|
|
175
|
+
* query runs longer than its expected execution time.
|
|
176
|
+
*/
|
|
177
|
+
export interface SlowQueryInfo {
|
|
178
|
+
/** The SQL text that was executed. */
|
|
179
|
+
sql: string;
|
|
180
|
+
/** The query parameters, if any. */
|
|
181
|
+
params?: any[];
|
|
182
|
+
/** Actual execution time in milliseconds. */
|
|
183
|
+
durationMs: number;
|
|
184
|
+
/** The threshold that was exceeded, in milliseconds. */
|
|
185
|
+
thresholdMs: number;
|
|
186
|
+
/**
|
|
187
|
+
* Call stack of the user code that initiated the query, with linkgress
|
|
188
|
+
* internal frames removed — the top frame is the call site of the terminal
|
|
189
|
+
* method (`.toList()`, `.firstOrDefault()`, `.count()`, ...). Empty string if
|
|
190
|
+
* no user frames could be resolved.
|
|
191
|
+
*/
|
|
192
|
+
stack: string;
|
|
127
193
|
}
|
|
128
194
|
/**
|
|
129
195
|
* Time trace entry for a single operation
|
|
@@ -160,7 +226,7 @@ export declare class TimeTracer {
|
|
|
160
226
|
private currentPhase;
|
|
161
227
|
private phaseStartTime;
|
|
162
228
|
private phases;
|
|
163
|
-
constructor(enabled: boolean, logger?: ((message: string,
|
|
229
|
+
constructor(enabled: boolean, logger?: ((message: string, section?: LogSection) => void) | undefined);
|
|
164
230
|
/**
|
|
165
231
|
* Start timing a phase
|
|
166
232
|
*/
|
|
@@ -196,7 +262,64 @@ export type LoggingOptions = QueryOptions;
|
|
|
196
262
|
export declare class QueryExecutor {
|
|
197
263
|
private client;
|
|
198
264
|
private options;
|
|
199
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Per-query timeout override (ms) set via `.withTimeout()`. Threaded down to
|
|
267
|
+
* the driver as `QueryExecutionOptions.timeoutMs`. `undefined` means no
|
|
268
|
+
* override (the connection-level default, if any, applies).
|
|
269
|
+
*/
|
|
270
|
+
private overrideTimeoutMs?;
|
|
271
|
+
/**
|
|
272
|
+
* Per-query "expected execution time" override (ms) set via
|
|
273
|
+
* `.expectedExecutionTime()`. If the query runs longer than this,
|
|
274
|
+
* `onQueryTakingTooLong` fires. `undefined` means use the context default.
|
|
275
|
+
*/
|
|
276
|
+
private overrideExpectedMs?;
|
|
277
|
+
constructor(client: DatabaseClient, options?: QueryOptions,
|
|
278
|
+
/**
|
|
279
|
+
* Per-query timeout override (ms) set via `.withTimeout()`. Threaded down to
|
|
280
|
+
* the driver as `QueryExecutionOptions.timeoutMs`. `undefined` means no
|
|
281
|
+
* override (the connection-level default, if any, applies).
|
|
282
|
+
*/
|
|
283
|
+
overrideTimeoutMs?: number | undefined,
|
|
284
|
+
/**
|
|
285
|
+
* Per-query "expected execution time" override (ms) set via
|
|
286
|
+
* `.expectedExecutionTime()`. If the query runs longer than this,
|
|
287
|
+
* `onQueryTakingTooLong` fires. `undefined` means use the context default.
|
|
288
|
+
*/
|
|
289
|
+
overrideExpectedMs?: number | undefined);
|
|
290
|
+
/**
|
|
291
|
+
* Build the per-query execution options (binary protocol + timeout override),
|
|
292
|
+
* or `undefined` when neither is set so the driver takes its fast path.
|
|
293
|
+
*/
|
|
294
|
+
private buildExecutionOptions;
|
|
295
|
+
/**
|
|
296
|
+
* Return a new executor sharing this one's client and options but applying the
|
|
297
|
+
* given per-query timeout override (ms). Pass `0` to disable the timeout for
|
|
298
|
+
* the derived executor. Used by `.withTimeout()` on the query builders.
|
|
299
|
+
*/
|
|
300
|
+
withTimeout(timeoutMs: number): QueryExecutor;
|
|
301
|
+
/**
|
|
302
|
+
* Return a new executor that flags this query as expected to finish within
|
|
303
|
+
* `expectedMs` — if it runs longer, `onQueryTakingTooLong` fires. Used by
|
|
304
|
+
* `.expectedExecutionTime()` on the query builders.
|
|
305
|
+
*/
|
|
306
|
+
withExpectedExecutionTime(expectedMs: number): QueryExecutor;
|
|
307
|
+
/** Whether slow-query detection is active (a callback is configured). */
|
|
308
|
+
private get slowQueryEnabled();
|
|
309
|
+
/** Effective "too long" threshold for the current query (ms). */
|
|
310
|
+
private get expectedExecutionMs();
|
|
311
|
+
/**
|
|
312
|
+
* Begin timing/stack capture for a query. Returns `undefined` when neither
|
|
313
|
+
* execution-time logging nor slow-query detection is active (zero overhead).
|
|
314
|
+
* The stack is captured here — synchronously, inside the caller's call chain —
|
|
315
|
+
* so the slow-query callback can report the user's code, not an async frame.
|
|
316
|
+
*/
|
|
317
|
+
private beginTiming;
|
|
318
|
+
/**
|
|
319
|
+
* Finish timing: log execution time (if enabled) and fire the slow-query
|
|
320
|
+
* callback (if enabled and the expected threshold was exceeded).
|
|
321
|
+
*/
|
|
322
|
+
private finishTiming;
|
|
200
323
|
query(sql: string, params?: any[]): Promise<QueryResult>;
|
|
201
324
|
/**
|
|
202
325
|
* Execute a multi-statement query using the simple protocol (no parameters)
|
|
@@ -445,6 +568,23 @@ export declare class TableAccessor<TBuilder extends TableBuilder<any>> {
|
|
|
445
568
|
* ```
|
|
446
569
|
*/
|
|
447
570
|
withQueryOptions(options: QueryOptions): TableAccessor<TBuilder>;
|
|
571
|
+
/**
|
|
572
|
+
* Set a per-query timeout (ms) applied to every query and CRUD operation
|
|
573
|
+
* started from the returned accessor. Each such query is wrapped individually
|
|
574
|
+
* (`SET LOCAL statement_timeout`); pass `0` to disable. Overrides the
|
|
575
|
+
* connection-level default. On timeout a `QueryTimeoutError` is thrown.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* await db.users.withTimeout(5000).where(u => gt(u.id, 0)).toList();
|
|
579
|
+
*/
|
|
580
|
+
withTimeout(timeoutMs: number): TableAccessor<TBuilder>;
|
|
581
|
+
/**
|
|
582
|
+
* Mark queries started from the returned accessor as expected to finish within
|
|
583
|
+
* `expectedMs` (ms). If a query runs longer, the context's
|
|
584
|
+
* `onQueryTakingTooLong` callback fires — the query is NOT cancelled (use
|
|
585
|
+
* `.withTimeout()` for that). Overrides the context's `longRunningQueryThreshold`.
|
|
586
|
+
*/
|
|
587
|
+
expectedExecutionTime(expectedMs: number): TableAccessor<TBuilder>;
|
|
448
588
|
/**
|
|
449
589
|
* Start a select query with automatic type inference
|
|
450
590
|
* UnwrapSelection extracts the value types from SqlFragment<T> expressions
|
|
@@ -756,6 +896,18 @@ export interface EntityCollectionQueryWithSelect<TEntity extends DbEntity, TSele
|
|
|
756
896
|
* ```
|
|
757
897
|
*/
|
|
758
898
|
export interface IEntityQueryable<TEntity extends DbEntity> {
|
|
899
|
+
/**
|
|
900
|
+
* Set a per-query timeout (ms) for this query, overriding the connection-level
|
|
901
|
+
* default. Only this query is wrapped (`SET LOCAL statement_timeout`); pass `0`
|
|
902
|
+
* to disable. On timeout a `QueryTimeoutError` is thrown.
|
|
903
|
+
*/
|
|
904
|
+
withTimeout(timeoutMs: number): IEntityQueryable<TEntity>;
|
|
905
|
+
/**
|
|
906
|
+
* Mark this query as expected to finish within `expectedMs` (ms). If it runs
|
|
907
|
+
* longer, the context's `onQueryTakingTooLong` callback fires (the query is
|
|
908
|
+
* NOT cancelled). Overrides the context's `longRunningQueryThreshold`.
|
|
909
|
+
*/
|
|
910
|
+
expectedExecutionTime(expectedMs: number): IEntityQueryable<TEntity>;
|
|
759
911
|
/**
|
|
760
912
|
* Add a WHERE condition. Multiple where() calls are chained with AND logic.
|
|
761
913
|
*/
|
|
@@ -863,6 +1015,18 @@ export interface IEntityQueryable<TEntity extends DbEntity> {
|
|
|
863
1015
|
* Results automatically unwrap DbColumn<T> to T and SqlFragment<T> to T
|
|
864
1016
|
*/
|
|
865
1017
|
export interface EntitySelectQueryBuilder<TEntity extends DbEntity, TSelection> {
|
|
1018
|
+
/**
|
|
1019
|
+
* Set a per-query timeout (ms) for this query, overriding the connection-level
|
|
1020
|
+
* default. Only this query is wrapped (`SET LOCAL statement_timeout`); pass `0`
|
|
1021
|
+
* to disable. On timeout a `QueryTimeoutError` is thrown.
|
|
1022
|
+
*/
|
|
1023
|
+
withTimeout(timeoutMs: number): EntitySelectQueryBuilder<TEntity, TSelection>;
|
|
1024
|
+
/**
|
|
1025
|
+
* Mark this query as expected to finish within `expectedMs` (ms). If it runs
|
|
1026
|
+
* longer, the context's `onQueryTakingTooLong` callback fires (the query is
|
|
1027
|
+
* NOT cancelled). Overrides the context's `longRunningQueryThreshold`.
|
|
1028
|
+
*/
|
|
1029
|
+
expectedExecutionTime(expectedMs: number): EntitySelectQueryBuilder<TEntity, TSelection>;
|
|
866
1030
|
select<TNewSelection>(selector: (entity: TSelection extends DbEntity ? EntityQuery<TSelection> : TSelection) => TNewSelection): EntitySelectQueryBuilder<TEntity, UnwrapSelection<TNewSelection>>;
|
|
867
1031
|
selectDistinct<TNewSelection>(selector: (entity: TSelection extends DbEntity ? EntityQuery<TSelection> : TSelection) => TNewSelection): EntitySelectQueryBuilder<TEntity, UnwrapSelection<TNewSelection>>;
|
|
868
1032
|
where(condition: (entity: TSelection extends DbEntity ? EntityQuery<TSelection> : ToFieldRefs<TSelection>) => Condition): EntitySelectQueryBuilder<TEntity, TSelection>;
|
|
@@ -1180,6 +1344,33 @@ export declare class DbEntityTable<TEntity extends DbEntity> {
|
|
|
1180
1344
|
* ```
|
|
1181
1345
|
*/
|
|
1182
1346
|
withQueryOptions(options: QueryOptions): DbEntityTable<TEntity>;
|
|
1347
|
+
/**
|
|
1348
|
+
* Set a per-query timeout (ms) applied to every query and CRUD operation
|
|
1349
|
+
* started from the returned table. Each such query is wrapped individually
|
|
1350
|
+
* (`SET LOCAL statement_timeout`); pass `0` to disable. Overrides the
|
|
1351
|
+
* connection-level default. On timeout a `QueryTimeoutError` is thrown.
|
|
1352
|
+
*
|
|
1353
|
+
* @example
|
|
1354
|
+
* await db.users.withTimeout(5000).where(u => gt(u.id, 0)).toList();
|
|
1355
|
+
*/
|
|
1356
|
+
withTimeout(timeoutMs: number): DbEntityTable<TEntity>;
|
|
1357
|
+
/**
|
|
1358
|
+
* Mark queries started from the returned table as expected to finish within
|
|
1359
|
+
* `expectedMs` (ms). If a query runs longer, the context's
|
|
1360
|
+
* `onQueryTakingTooLong` callback fires — the query is NOT cancelled (use
|
|
1361
|
+
* `.withTimeout()` for that). Overrides the context's `longRunningQueryThreshold`.
|
|
1362
|
+
*
|
|
1363
|
+
* @example
|
|
1364
|
+
* await db.users.expectedExecutionTime(2000).where(u => gt(u.id, 0)).toList();
|
|
1365
|
+
*/
|
|
1366
|
+
expectedExecutionTime(expectedMs: number): DbEntityTable<TEntity>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Build a derived table whose context surfaces a transformed executor (via a
|
|
1369
|
+
* proxy context, threaded into this table's accessor). Shared by
|
|
1370
|
+
* `.withTimeout()` and `.expectedExecutionTime()`.
|
|
1371
|
+
* @internal
|
|
1372
|
+
*/
|
|
1373
|
+
private _deriveWithExecutor;
|
|
1183
1374
|
/**
|
|
1184
1375
|
* Select all records - returns full entities with unwrapped DbColumns
|
|
1185
1376
|
*/
|