@relaybus/postgres 0.2.0 → 0.3.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/README.md +28 -2
- package/dist/chunk-NNZJR5AB.js +12 -0
- package/dist/chunk-NNZJR5AB.js.map +1 -0
- package/dist/drizzle.cjs +13 -5
- package/dist/drizzle.cjs.map +1 -1
- package/dist/drizzle.d.cts +1 -1
- package/dist/drizzle.d.ts +1 -1
- package/dist/drizzle.js +6 -4
- package/dist/drizzle.js.map +1 -1
- package/dist/{executor-VZGmsMX4.d.cts → executor-CfJgktC6.d.cts} +17 -0
- package/dist/{executor-VZGmsMX4.d.ts → executor-CfJgktC6.d.ts} +17 -0
- package/dist/index.cjs +2215 -1690
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +50 -9
- package/dist/index.d.ts +50 -9
- package/dist/index.js +2217 -1693
- package/dist/index.js.map +1 -1
- package/dist/knex.cjs +14 -4
- package/dist/knex.cjs.map +1 -1
- package/dist/knex.d.cts +1 -1
- package/dist/knex.d.ts +1 -1
- package/dist/knex.js +6 -4
- package/dist/knex.js.map +1 -1
- package/dist/kysely.cjs +13 -5
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +1 -1
- package/dist/kysely.d.ts +1 -1
- package/dist/kysely.js +6 -5
- package/dist/kysely.js.map +1 -1
- package/dist/prisma.cjs +14 -4
- package/dist/prisma.cjs.map +1 -1
- package/dist/prisma.d.cts +1 -1
- package/dist/prisma.d.ts +1 -1
- package/dist/prisma.js +7 -4
- package/dist/prisma.js.map +1 -1
- package/dist/typeorm.cjs +14 -4
- package/dist/typeorm.cjs.map +1 -1
- package/dist/typeorm.d.cts +1 -1
- package/dist/typeorm.d.ts +1 -1
- package/dist/typeorm.js +7 -4
- package/dist/typeorm.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -50,7 +50,9 @@ try {
|
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
The transaction handle is a `pg` `PoolClient`. If you pass `connectionString` instead of `pool`, the store creates and,
|
|
53
|
-
on `close()`, ends its own pool. A pool or executor you pass in is never closed by the store.
|
|
53
|
+
on `close()`, ends its own pool. A pool or executor you pass in is never closed by the store. When `bus.stop()` runs past
|
|
54
|
+
its deadline, the store destroys the connections it opened itself (its own pool's and the one it listens for
|
|
55
|
+
notifications on), so a query stuck on a lock fails at once instead of holding the shutdown; your pool is left as is.
|
|
54
56
|
|
|
55
57
|
### Other libraries
|
|
56
58
|
|
|
@@ -78,6 +80,28 @@ await db.transaction().execute(async (trx) => {
|
|
|
78
80
|
Use `transactionResolver` (for example from `@nestjs-cls/transactional`) to avoid passing the handle explicitly.
|
|
79
81
|
For another client, implement `PostgresExecutor` (`transaction` and `query`; about 20 lines).
|
|
80
82
|
|
|
83
|
+
**Transaction time budget.** `bus.transaction` passes the bus `transactionTimeout` (default `'5s'`) to the store,
|
|
84
|
+
which sets it with `set_config(..., true)` (the `SET LOCAL` scope, gone after the transaction) as
|
|
85
|
+
`statement_timeout`. Executors that declare `sessionTimeouts: true` (`PgExecutor` does; it listens for `error` on the
|
|
86
|
+
connection while the transaction runs) also get `idle_in_transaction_session_timeout` and, on PostgreSQL 17+,
|
|
87
|
+
`transaction_timeout`, so a transaction left idle by a slow external call is ended by the server and its locks are
|
|
88
|
+
released. The other adapters keep only `statement_timeout`, because a server-ended session would emit an unhandled
|
|
89
|
+
`error` on their checked-out `pg` connection; the bus still rolls back an overrun before the commit. The caller gets a
|
|
90
|
+
`TransactionTimeoutError` with the server error as `cause`. `PgExecutor` sends the settings in the round trip of `BEGIN`
|
|
91
|
+
(the optional executor method `transactionWithBudget`), so the budget costs no extra round trip; executors without it
|
|
92
|
+
send them as the first statement of the transaction.
|
|
93
|
+
|
|
94
|
+
Where the budget lives depends on who owns the pool:
|
|
95
|
+
|
|
96
|
+
- **A pool the store created** (`connectionString`/`poolConfig`): each connection keeps the budget as a session setting.
|
|
97
|
+
The first `bus.transaction` on a connection sets it with `BEGIN`; later ones send nothing extra, so a publish costs
|
|
98
|
+
what it did without a budget. A transaction without a budget (setup, a transactional handler) puts the session
|
|
99
|
+
defaults back in its `BEGIN`. Statements outside a transaction (claims, completions) run under the budget the
|
|
100
|
+
connection last got. With `preparedStatements: false` (a pooler in transaction mode, which would carry session
|
|
101
|
+
settings to other clients) the budget stays transaction-scoped.
|
|
102
|
+
- **A pool or executor you pass in**: the budget is transaction-scoped (`SET LOCAL` semantics), set with `BEGIN` by
|
|
103
|
+
`PgExecutor` and by its own statement for the other adapters. Session settings of your pool are never changed.
|
|
104
|
+
|
|
81
105
|
**Prisma is not integration-tested yet.** The adapter is typed structurally (no Prisma dependency) and unit-tested
|
|
82
106
|
against a fake client only. Prisma interactive transactions default to a 5 s timeout, so pass
|
|
83
107
|
`createPrismaExecutor(prisma, { timeout, maxWait })` if handlers run longer.
|
|
@@ -97,7 +121,7 @@ against a fake client only. Prisma interactive transactions default to a 5 s tim
|
|
|
97
121
|
| `wakeUp` | `'notify'` | `'notify'`: coalesced `NOTIFY` + `LISTEN` wake other processes. `'poll'`: no notifications, other processes poll. |
|
|
98
122
|
|
|
99
123
|
**Pool errors.** A pool created from `connectionString` gets an `error` listener that logs through `logger`
|
|
100
|
-
(`[PostgresEventStore](
|
|
124
|
+
(`[PostgresEventStore](connect) Idle connection failed ...`); `pg` then replaces the dead connection, so a failover
|
|
101
125
|
or `pg_terminate_backend` of an idle connection does not crash the process. A `pool` you pass in is yours: attach
|
|
102
126
|
`pool.on('error', ...)` to it yourself, because without a listener `pg` re-throws the error as an uncaught exception.
|
|
103
127
|
|
|
@@ -139,6 +163,8 @@ same on every database. The tables are created with aggressive autovacuum settin
|
|
|
139
163
|
|
|
140
164
|
## Upgrading from 0.1.0
|
|
141
165
|
|
|
166
|
+
The step-by-step guide, including `completionHistory` and PgBouncer settings, is [Upgrading from 0.1 to 0.2](https://berkcansavur.github.io/relaybus/upgrading).
|
|
167
|
+
|
|
142
168
|
`setup()` upgrades a 0.1.0 schema in place, in one transaction under the same advisory lock, and is safe to run again:
|
|
143
169
|
it adds `lane` to every delivery (hash of the key, or of the event id) and `handlers` to every event (from the
|
|
144
170
|
existing deliveries), turns `processing` deliveries into `pending` (their attempt stays counted, as a lost lease would
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/adapter-executor.ts
|
|
2
|
+
function adapterExecutor(client) {
|
|
3
|
+
return {
|
|
4
|
+
transaction: client.transaction,
|
|
5
|
+
// eslint-disable-next-line relaybus/max-two-params -- PostgresExecutor port signature
|
|
6
|
+
query: (sql, parameters, transaction) => client.run(transaction ?? client.root, { sql, parameters })
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { adapterExecutor };
|
|
11
|
+
//# sourceMappingURL=chunk-NNZJR5AB.js.map
|
|
12
|
+
//# sourceMappingURL=chunk-NNZJR5AB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/adapter-executor.ts"],"names":[],"mappings":";AAqBO,SAAS,gBACd,MAAA,EAC8B;AAC9B,EAAA,OAAO;AAAA,IACL,aAAa,MAAA,CAAO,WAAA;AAAA;AAAA,IAEpB,KAAA,EAAO,CAAC,GAAA,EAAK,UAAA,EAAY,WAAA,KACvB,MAAA,CAAO,GAAA,CAAI,WAAA,IAAe,MAAA,CAAO,IAAA,EAAM,EAAE,GAAA,EAAK,YAAY;AAAA,GAC9D;AACF","file":"chunk-NNZJR5AB.js","sourcesContent":["import type { PostgresExecutor, PostgresParameter, PostgresRow } from './executor.js';\n\n/** One statement the store sends, with its positional parameters. */\nexport type AdapterStatement = {\n readonly sql: string;\n readonly parameters: readonly PostgresParameter[];\n};\n\n/** What an adapter supplies: where statements run outside a transaction, and how it runs one. */\nexport type AdapterClient<TQueryable> = {\n /** The instance itself: statements outside a transaction run on it. */\n readonly root: TQueryable;\n readonly transaction: PostgresExecutor<TQueryable>['transaction'];\n /** Runs one statement on the caller's transaction, else on the root. */\n readonly run: (queryable: TQueryable, statement: AdapterStatement) => Promise<PostgresRow[]>;\n};\n\n/**\n * The executor every library adapter shares: a statement runs on the transaction it is given,\n * else on the root instance. An adapter supplies only how its library runs one statement.\n */\nexport function adapterExecutor<TQueryable>(\n client: AdapterClient<TQueryable>,\n): PostgresExecutor<TQueryable> {\n return {\n transaction: client.transaction,\n // eslint-disable-next-line relaybus/max-two-params -- PostgresExecutor port signature\n query: (sql, parameters, transaction) =>\n client.run(transaction ?? client.root, { sql, parameters }),\n };\n}\n"]}
|
package/dist/drizzle.cjs
CHANGED
|
@@ -2,7 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
var drizzleOrm = require('drizzle-orm');
|
|
4
4
|
|
|
5
|
-
// src/
|
|
5
|
+
// src/adapter-executor.ts
|
|
6
|
+
function adapterExecutor(client) {
|
|
7
|
+
return {
|
|
8
|
+
transaction: client.transaction,
|
|
9
|
+
// eslint-disable-next-line relaybus/max-two-params -- PostgresExecutor port signature
|
|
10
|
+
query: (sql, parameters, transaction) => client.run(transaction ?? client.root, { sql, parameters })
|
|
11
|
+
};
|
|
12
|
+
}
|
|
6
13
|
|
|
7
14
|
// src/positional-sql.ts
|
|
8
15
|
function splitPositionalSql(sql) {
|
|
@@ -18,16 +25,17 @@ function splitPositionalSql(sql) {
|
|
|
18
25
|
|
|
19
26
|
// src/drizzle/drizzle-executor.ts
|
|
20
27
|
function createDrizzleExecutor(database) {
|
|
21
|
-
return {
|
|
28
|
+
return adapterExecutor({
|
|
29
|
+
root: database,
|
|
22
30
|
transaction: (work) => database.transaction(work),
|
|
23
|
-
async
|
|
31
|
+
async run(queryable, { sql, parameters }) {
|
|
24
32
|
const chunks = splitPositionalSql(sql).map(
|
|
25
33
|
(part) => typeof part === "string" ? drizzleOrm.sql.raw(part) : drizzleOrm.sql.param(parameters[part.parameterIndex])
|
|
26
34
|
);
|
|
27
|
-
const result = await
|
|
35
|
+
const result = await queryable.execute(drizzleOrm.sql.join(chunks));
|
|
28
36
|
return result.rows;
|
|
29
37
|
}
|
|
30
|
-
};
|
|
38
|
+
});
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
exports.createDrizzleExecutor = createDrizzleExecutor;
|
package/dist/drizzle.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/positional-sql.ts","../src/drizzle/drizzle-executor.ts"],"names":["drizzleSql"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/adapter-executor.ts","../src/positional-sql.ts","../src/drizzle/drizzle-executor.ts"],"names":["drizzleSql"],"mappings":";;;;;AAqBO,SAAS,gBACd,MAAA,EAC8B;AAC9B,EAAA,OAAO;AAAA,IACL,aAAa,MAAA,CAAO,WAAA;AAAA;AAAA,IAEpB,KAAA,EAAO,CAAC,GAAA,EAAK,UAAA,EAAY,WAAA,KACvB,MAAA,CAAO,GAAA,CAAI,WAAA,IAAe,MAAA,CAAO,IAAA,EAAM,EAAE,GAAA,EAAK,YAAY;AAAA,GAC9D;AACF;;;ACrBO,SAAS,mBAAmB,GAAA,EAAkC;AACnE,EAAA,MAAM,QAA6B,EAAC;AACpC,EAAA,IAAI,SAAA,GAAY,CAAA;AAChB,EAAA,KAAA,MAAW,KAAA,IAAS,GAAA,CAAI,QAAA,CAAS,UAAU,CAAA,EAAG;AAC5C,IAAA,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,KAAA,CAAM,SAAA,EAAW,MAAM,KAAK,CAAA,EAAG,EAAE,cAAA,EAAgB,OAAO,KAAA,CAAM,CAAC,CAAC,CAAA,GAAI,GAAG,CAAA;AACtF,IAAA,SAAA,GAAY,KAAA,CAAM,KAAA,GAAQ,KAAA,CAAM,CAAC,CAAA,CAAE,MAAA;AAAA,EACrC;AACA,EAAA,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,KAAA,CAAM,SAAS,CAAC,CAAA;AAC/B,EAAA,OAAO,KAAA;AACT;;;ACCO,SAAS,sBAAsB,QAAA,EAA2D;AAC/F,EAAA,OAAO,eAAA,CAAkC;AAAA,IACvC,IAAA,EAAM,QAAA;AAAA,IACN,WAAA,EAAa,CAAC,IAAA,KAAS,QAAA,CAAS,YAAY,IAAI,CAAA;AAAA,IAChD,MAAM,GAAA,CAAI,SAAA,EAAW,EAAE,GAAA,EAAK,YAAW,EAAG;AACxC,MAAA,MAAM,MAAA,GAAS,kBAAA,CAAmB,GAAG,CAAA,CAAE,GAAA;AAAA,QAAI,CAAC,IAAA,KAC1C,OAAO,IAAA,KAAS,WACZA,cAAA,CAAW,GAAA,CAAI,IAAI,CAAA,GACnBA,cAAA,CAAW,KAAA,CAAM,UAAA,CAAW,IAAA,CAAK,cAAc,CAAC;AAAA,OACtD;AACA,MAAA,MAAM,SAAS,MAAM,SAAA,CAAU,QAAQA,cAAA,CAAW,IAAA,CAAK,MAAM,CAAC,CAAA;AAC9D,MAAA,OAAO,MAAA,CAAO,IAAA;AAAA,IAChB;AAAA,GACD,CAAA;AACH","file":"drizzle.cjs","sourcesContent":["import type { PostgresExecutor, PostgresParameter, PostgresRow } from './executor.js';\n\n/** One statement the store sends, with its positional parameters. */\nexport type AdapterStatement = {\n readonly sql: string;\n readonly parameters: readonly PostgresParameter[];\n};\n\n/** What an adapter supplies: where statements run outside a transaction, and how it runs one. */\nexport type AdapterClient<TQueryable> = {\n /** The instance itself: statements outside a transaction run on it. */\n readonly root: TQueryable;\n readonly transaction: PostgresExecutor<TQueryable>['transaction'];\n /** Runs one statement on the caller's transaction, else on the root. */\n readonly run: (queryable: TQueryable, statement: AdapterStatement) => Promise<PostgresRow[]>;\n};\n\n/**\n * The executor every library adapter shares: a statement runs on the transaction it is given,\n * else on the root instance. An adapter supplies only how its library runs one statement.\n */\nexport function adapterExecutor<TQueryable>(\n client: AdapterClient<TQueryable>,\n): PostgresExecutor<TQueryable> {\n return {\n transaction: client.transaction,\n // eslint-disable-next-line relaybus/max-two-params -- PostgresExecutor port signature\n query: (sql, parameters, transaction) =>\n client.run(transaction ?? client.root, { sql, parameters }),\n };\n}\n","/** A piece of SQL text, or a reference to the (zero-based) parameter that stands at this position. */\nexport type PositionalSqlPart = string | { readonly parameterIndex: number };\n\n/**\n * Splits SQL written with PostgreSQL `$1, $2, ...` placeholders into text and\n * parameter references, in order of appearance. A placeholder used twice\n * appears twice. Adapters for libraries with their own placeholder syntax\n * (Knex `?`, Drizzle parameter chunks) rebuild the statement from the parts.\n */\nexport function splitPositionalSql(sql: string): PositionalSqlPart[] {\n const parts: PositionalSqlPart[] = [];\n let textStart = 0;\n for (const match of sql.matchAll(/\\$(\\d+)/g)) {\n parts.push(sql.slice(textStart, match.index), { parameterIndex: Number(match[1]) - 1 });\n textStart = match.index + match[0].length;\n }\n parts.push(sql.slice(textStart));\n return parts;\n}\n","import { adapterExecutor } from '../adapter-executor.js';\nimport { sql as drizzleSql, type SQL } from 'drizzle-orm';\nimport type { PostgresExecutor } from '../executor.js';\nimport { splitPositionalSql } from '../positional-sql.js';\n\n/** What a Drizzle database and a Drizzle transaction have in common. */\nexport interface DrizzleQueryable {\n execute(query: SQL): PromiseLike<{ readonly rows: Record<string, unknown>[] }>;\n}\n\n/** The part of a Drizzle `node-postgres` database the executor uses. */\nexport interface DrizzleLike extends DrizzleQueryable {\n transaction<T>(work: (transaction: DrizzleQueryable) => Promise<T>): Promise<T>;\n}\n\n/**\n * Executor for Drizzle with the `node-postgres` driver. The transaction handle\n * is a Drizzle transaction: pass `tx` from `db.transaction(async (tx) => ...)`.\n */\nexport function createDrizzleExecutor(database: DrizzleLike): PostgresExecutor<DrizzleQueryable> {\n return adapterExecutor<DrizzleQueryable>({\n root: database,\n transaction: (work) => database.transaction(work),\n async run(queryable, { sql, parameters }) {\n const chunks = splitPositionalSql(sql).map((part) =>\n typeof part === 'string'\n ? drizzleSql.raw(part)\n : drizzleSql.param(parameters[part.parameterIndex]),\n );\n const result = await queryable.execute(drizzleSql.join(chunks));\n return result.rows;\n },\n });\n}\n"]}
|
package/dist/drizzle.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import { P as PostgresExecutor } from './executor-
|
|
2
|
+
import { P as PostgresExecutor } from './executor-CfJgktC6.cjs';
|
|
3
3
|
|
|
4
4
|
/** What a Drizzle database and a Drizzle transaction have in common. */
|
|
5
5
|
interface DrizzleQueryable {
|
package/dist/drizzle.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import { P as PostgresExecutor } from './executor-
|
|
2
|
+
import { P as PostgresExecutor } from './executor-CfJgktC6.js';
|
|
3
3
|
|
|
4
4
|
/** What a Drizzle database and a Drizzle transaction have in common. */
|
|
5
5
|
interface DrizzleQueryable {
|
package/dist/drizzle.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { splitPositionalSql } from './chunk-UUFSUL2M.js';
|
|
2
|
+
import { adapterExecutor } from './chunk-NNZJR5AB.js';
|
|
2
3
|
import { sql } from 'drizzle-orm';
|
|
3
4
|
|
|
4
5
|
function createDrizzleExecutor(database) {
|
|
5
|
-
return {
|
|
6
|
+
return adapterExecutor({
|
|
7
|
+
root: database,
|
|
6
8
|
transaction: (work) => database.transaction(work),
|
|
7
|
-
async
|
|
9
|
+
async run(queryable, { sql: sql$1, parameters }) {
|
|
8
10
|
const chunks = splitPositionalSql(sql$1).map(
|
|
9
11
|
(part) => typeof part === "string" ? sql.raw(part) : sql.param(parameters[part.parameterIndex])
|
|
10
12
|
);
|
|
11
|
-
const result = await
|
|
13
|
+
const result = await queryable.execute(sql.join(chunks));
|
|
12
14
|
return result.rows;
|
|
13
15
|
}
|
|
14
|
-
};
|
|
16
|
+
});
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export { createDrizzleExecutor };
|
package/dist/drizzle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/drizzle/drizzle-executor.ts"],"names":["sql","drizzleSql"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/drizzle/drizzle-executor.ts"],"names":["sql","drizzleSql"],"mappings":";;;;AAmBO,SAAS,sBAAsB,QAAA,EAA2D;AAC/F,EAAA,OAAO,eAAA,CAAkC;AAAA,IACvC,IAAA,EAAM,QAAA;AAAA,IACN,WAAA,EAAa,CAAC,IAAA,KAAS,QAAA,CAAS,YAAY,IAAI,CAAA;AAAA,IAChD,MAAM,GAAA,CAAI,SAAA,EAAW,OAAEA,KAAA,EAAK,YAAW,EAAG;AACxC,MAAA,MAAM,MAAA,GAAS,kBAAA,CAAmBA,KAAG,CAAA,CAAE,GAAA;AAAA,QAAI,CAAC,IAAA,KAC1C,OAAO,IAAA,KAAS,WACZC,GAAA,CAAW,GAAA,CAAI,IAAI,CAAA,GACnBA,GAAA,CAAW,KAAA,CAAM,UAAA,CAAW,IAAA,CAAK,cAAc,CAAC;AAAA,OACtD;AACA,MAAA,MAAM,SAAS,MAAM,SAAA,CAAU,QAAQA,GAAA,CAAW,IAAA,CAAK,MAAM,CAAC,CAAA;AAC9D,MAAA,OAAO,MAAA,CAAO,IAAA;AAAA,IAChB;AAAA,GACD,CAAA;AACH","file":"drizzle.js","sourcesContent":["import { adapterExecutor } from '../adapter-executor.js';\nimport { sql as drizzleSql, type SQL } from 'drizzle-orm';\nimport type { PostgresExecutor } from '../executor.js';\nimport { splitPositionalSql } from '../positional-sql.js';\n\n/** What a Drizzle database and a Drizzle transaction have in common. */\nexport interface DrizzleQueryable {\n execute(query: SQL): PromiseLike<{ readonly rows: Record<string, unknown>[] }>;\n}\n\n/** The part of a Drizzle `node-postgres` database the executor uses. */\nexport interface DrizzleLike extends DrizzleQueryable {\n transaction<T>(work: (transaction: DrizzleQueryable) => Promise<T>): Promise<T>;\n}\n\n/**\n * Executor for Drizzle with the `node-postgres` driver. The transaction handle\n * is a Drizzle transaction: pass `tx` from `db.transaction(async (tx) => ...)`.\n */\nexport function createDrizzleExecutor(database: DrizzleLike): PostgresExecutor<DrizzleQueryable> {\n return adapterExecutor<DrizzleQueryable>({\n root: database,\n transaction: (work) => database.transaction(work),\n async run(queryable, { sql, parameters }) {\n const chunks = splitPositionalSql(sql).map((part) =>\n typeof part === 'string'\n ? drizzleSql.raw(part)\n : drizzleSql.param(parameters[part.parameterIndex]),\n );\n const result = await queryable.execute(drizzleSql.join(chunks));\n return result.rows;\n },\n });\n}\n"]}
|
|
@@ -27,7 +27,24 @@ interface PostgresQueryOptions {
|
|
|
27
27
|
* - `options` are hints ({@link PostgresQueryOptions}); ignoring them is correct, only slower.
|
|
28
28
|
*/
|
|
29
29
|
interface PostgresExecutor<TTransaction> {
|
|
30
|
+
/**
|
|
31
|
+
* True when the process keeps running if the server ends the session of an open transaction
|
|
32
|
+
* (an `error` listener is on the connection while the transaction runs). The store then holds
|
|
33
|
+
* `bus.transaction` to its budget with `idle_in_transaction_session_timeout` and, on PostgreSQL
|
|
34
|
+
* 17+, `transaction_timeout` as well as `statement_timeout`. Without it only `statement_timeout`
|
|
35
|
+
* is set: a `pg` client checked out by another library without an `error` listener would crash
|
|
36
|
+
* the process with an unhandled `error` event when the server ends its session. `PgExecutor`
|
|
37
|
+
* sets it.
|
|
38
|
+
*/
|
|
39
|
+
readonly sessionTimeouts?: boolean;
|
|
30
40
|
transaction<T>(work: (transaction: TTransaction) => Promise<T>): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Optional. Opens a transaction like {@link PostgresExecutor.transaction} that the server holds to
|
|
43
|
+
* `timeoutMs` (`statement_timeout`, plus the session timeouts when {@link sessionTimeouts} is set),
|
|
44
|
+
* set in the round trip of its `BEGIN`. Without it the store sets the budget with a statement of
|
|
45
|
+
* its own, one round trip more per `bus.transaction`. `PgExecutor` implements it.
|
|
46
|
+
*/
|
|
47
|
+
transactionWithBudget?<T>(work: (transaction: TTransaction) => Promise<T>, timeoutMs: number): Promise<T>;
|
|
31
48
|
query(sql: string, parameters: readonly PostgresParameter[], transaction?: TTransaction, options?: PostgresQueryOptions): Promise<readonly PostgresRow[]>;
|
|
32
49
|
}
|
|
33
50
|
|
|
@@ -27,7 +27,24 @@ interface PostgresQueryOptions {
|
|
|
27
27
|
* - `options` are hints ({@link PostgresQueryOptions}); ignoring them is correct, only slower.
|
|
28
28
|
*/
|
|
29
29
|
interface PostgresExecutor<TTransaction> {
|
|
30
|
+
/**
|
|
31
|
+
* True when the process keeps running if the server ends the session of an open transaction
|
|
32
|
+
* (an `error` listener is on the connection while the transaction runs). The store then holds
|
|
33
|
+
* `bus.transaction` to its budget with `idle_in_transaction_session_timeout` and, on PostgreSQL
|
|
34
|
+
* 17+, `transaction_timeout` as well as `statement_timeout`. Without it only `statement_timeout`
|
|
35
|
+
* is set: a `pg` client checked out by another library without an `error` listener would crash
|
|
36
|
+
* the process with an unhandled `error` event when the server ends its session. `PgExecutor`
|
|
37
|
+
* sets it.
|
|
38
|
+
*/
|
|
39
|
+
readonly sessionTimeouts?: boolean;
|
|
30
40
|
transaction<T>(work: (transaction: TTransaction) => Promise<T>): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Optional. Opens a transaction like {@link PostgresExecutor.transaction} that the server holds to
|
|
43
|
+
* `timeoutMs` (`statement_timeout`, plus the session timeouts when {@link sessionTimeouts} is set),
|
|
44
|
+
* set in the round trip of its `BEGIN`. Without it the store sets the budget with a statement of
|
|
45
|
+
* its own, one round trip more per `bus.transaction`. `PgExecutor` implements it.
|
|
46
|
+
*/
|
|
47
|
+
transactionWithBudget?<T>(work: (transaction: TTransaction) => Promise<T>, timeoutMs: number): Promise<T>;
|
|
31
48
|
query(sql: string, parameters: readonly PostgresParameter[], transaction?: TTransaction, options?: PostgresQueryOptions): Promise<readonly PostgresRow[]>;
|
|
32
49
|
}
|
|
33
50
|
|