@relaybus/postgres 0.3.0 → 0.4.0
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 +29 -10
- package/dist/chunk-NNZJR5AB.js +12 -0
- package/dist/chunk-NNZJR5AB.js.map +1 -0
- package/dist/drizzle.cjs +13 -6
- package/dist/drizzle.cjs.map +1 -1
- package/dist/drizzle.d.cts +3 -2
- package/dist/drizzle.d.ts +3 -2
- package/dist/drizzle.js +6 -5
- package/dist/drizzle.js.map +1 -1
- package/dist/index.cjs +457 -404
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -2
- package/dist/index.d.ts +15 -2
- package/dist/index.js +458 -405
- package/dist/index.js.map +1 -1
- package/dist/knex.cjs +14 -5
- package/dist/knex.cjs.map +1 -1
- package/dist/knex.d.cts +3 -2
- package/dist/knex.d.ts +3 -2
- package/dist/knex.js +6 -5
- package/dist/knex.js.map +1 -1
- package/dist/kysely.cjs +13 -6
- package/dist/kysely.cjs.map +1 -1
- package/dist/kysely.d.cts +3 -2
- package/dist/kysely.d.ts +3 -2
- package/dist/kysely.js +6 -6
- package/dist/kysely.js.map +1 -1
- package/dist/prisma.cjs +14 -5
- package/dist/prisma.cjs.map +1 -1
- package/dist/prisma.d.cts +4 -4
- package/dist/prisma.d.ts +4 -4
- package/dist/prisma.js +7 -5
- package/dist/prisma.js.map +1 -1
- package/dist/typeorm.cjs +14 -5
- package/dist/typeorm.cjs.map +1 -1
- package/dist/typeorm.d.cts +3 -2
- package/dist/typeorm.d.ts +3 -2
- package/dist/typeorm.js +7 -5
- package/dist/typeorm.js.map +1 -1
- package/package.json +19 -12
package/README.md
CHANGED
|
@@ -102,15 +102,29 @@ Where the budget lives depends on who owns the pool:
|
|
|
102
102
|
- **A pool or executor you pass in**: the budget is transaction-scoped (`SET LOCAL` semantics), set with `BEGIN` by
|
|
103
103
|
`PgExecutor` and by its own statement for the other adapters. Session settings of your pool are never changed.
|
|
104
104
|
|
|
105
|
-
**Prisma is
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
**Prisma** is integration-tested with a generated Prisma Client 7.10 (and 6.19 in CI) on the `@prisma/adapter-pg`
|
|
106
|
+
driver adapter: the full event store contract, publishing in `prisma.$transaction`, rollback and concurrent
|
|
107
|
+
transactions. The adapter is typed structurally, so the package has no Prisma dependency. Prisma interactive
|
|
108
|
+
transactions default to a 5 s timeout, so pass `createPrismaExecutor(prisma, { timeout, maxWait })` if handlers run
|
|
109
|
+
longer.
|
|
110
|
+
|
|
111
|
+
**Give an ORM store the `pg` pool too.** ORMs send raw statements unprepared and offer no connection to `LISTEN` on.
|
|
112
|
+
Pass the `pg` pool your ORM's driver uses as `pool` next to `executor`: the statements the store sends outside your
|
|
113
|
+
transactions (the dispatcher's claims, completions and renewals) then run on it as prepared statements, and the
|
|
114
|
+
store listens for wake-ups, so an event published in your ORM transaction is dispatched right after that
|
|
115
|
+
transaction commits. Your transactions still go through the ORM, and the store never closes the pool.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const pool = new Pool({ connectionString });
|
|
119
|
+
const prisma = new PrismaClient({ adapter: new PrismaPg(pool) });
|
|
120
|
+
const store = new PostgresEventStore({ executor: createPrismaExecutor(prisma), pool });
|
|
121
|
+
```
|
|
108
122
|
|
|
109
123
|
## Options
|
|
110
124
|
|
|
111
125
|
| Option | Default | Meaning |
|
|
112
126
|
| ---------------------------------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
113
|
-
| `pool` / `connectionString` / `executor` | required, exactly one | How to reach the database.
|
|
127
|
+
| `pool` / `connectionString` / `executor` | required, exactly one | How to reach the database. With `executor`, `pool` may be given too (see above). |
|
|
114
128
|
| `poolConfig` | none | Extra `pg` pool settings when `connectionString` is used. |
|
|
115
129
|
| `schema` | `'public'` | Schema of the tables. Created by `setup()` when it is not `public`. |
|
|
116
130
|
| `tablePrefix` | `'relaybus_'` | Tables are `<prefix>events`, `<prefix>deliveries`, `<prefix>key_sequences`, `<prefix>lanes`. |
|
|
@@ -274,11 +288,16 @@ tool, run it as one transaction with the workers stopped. Running 0.1.0 and the
|
|
|
274
288
|
that channel (`<schema>.<prefix>deliveries`, hashed when longer than 63 characters) on one connection of its own,
|
|
275
289
|
opened with the pool's settings outside the pool, so an event published by any process runs within milliseconds
|
|
276
290
|
instead of at the next poll. A lost listening connection is replaced after a second; polling remains the safety
|
|
277
|
-
net, so a missed notification only costs latency.
|
|
278
|
-
|
|
291
|
+
net, so a missed notification only costs latency. The notification of a publish in your own transaction is sent
|
|
292
|
+
by PostgreSQL at its commit, however late that is, so the handler starts within milliseconds of the commit
|
|
293
|
+
(`wake-after-commit.integration.test.ts`). A store built on an `executor` listens only when it is given `pool`
|
|
294
|
+
as well; without it, it relies on polling and on the wake-ups of its own process after a publish (see
|
|
295
|
+
`bus.wake()`). `wakeUp: 'poll'` sends and listens for nothing.
|
|
279
296
|
- **Prepared statements.** With `preparedStatements: true` (the default) the publish, claim, completion and renewal
|
|
280
297
|
statements are named prepared statements: each connection parses and plans them once. Only `PgExecutor` (the
|
|
281
|
-
default `pool` / `connectionString` path
|
|
298
|
+
default `pool` / `connectionString` path, and the `pool` given next to an `executor`) prepares; the library
|
|
299
|
+
adapters send the statements of your transactions unprepared (a dispatch batch on an ORM store parses 2 statements
|
|
300
|
+
without `pool`, 0 with it: `perf-design-orm-executors.integration.test.ts`). See
|
|
282
301
|
`docs/performance/publish-path.md` for what that saves.
|
|
283
302
|
- **Pooling.** Claim, complete, extend and purge need a free connection besides your transactions; size the pool for
|
|
284
303
|
`dispatcher.concurrency` plus publishers; the listening connection comes on top of the pool's `max`. Listening and
|
|
@@ -310,12 +329,12 @@ tool, run it as one transaction with the workers stopped. Running 0.1.0 and the
|
|
|
310
329
|
## Testing
|
|
311
330
|
|
|
312
331
|
Integration tests use Testcontainers against `postgres:17-alpine` and `postgres:13-alpine` (override with
|
|
313
|
-
`RELAYBUS_POSTGRES_IMAGES`). Every adapter
|
|
314
|
-
transaction tests against the real database.
|
|
332
|
+
`RELAYBUS_POSTGRES_IMAGES`). Every adapter (Kysely, Knex, TypeORM, Drizzle, Prisma with and without `pool`) runs the
|
|
333
|
+
full `@relaybus/testing` event store contract plus transaction tests against the real database.
|
|
315
334
|
|
|
316
335
|
## When to use @relaybus/postgres, and when not to
|
|
317
336
|
|
|
318
|
-
Use it when your data lives in PostgreSQL 13 or newer and events must commit or roll back with it. It is not for MySQL or MongoDB (see `@relaybus/mongodb` for MongoDB)
|
|
337
|
+
Use it when your data lives in PostgreSQL 13 or newer and events must commit or roll back with it. It is not for MySQL or MongoDB (see `@relaybus/mongodb` for MongoDB).
|
|
319
338
|
|
|
320
339
|
Documentation: <https://berkcansavur.github.io/relaybus/packages/postgres>
|
|
321
340
|
|
|
@@ -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,17 +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
|
-
|
|
24
|
-
async query(sql, parameters, transaction) {
|
|
31
|
+
async run(queryable, { sql, parameters }) {
|
|
25
32
|
const chunks = splitPositionalSql(sql).map(
|
|
26
33
|
(part) => typeof part === "string" ? drizzleOrm.sql.raw(part) : drizzleOrm.sql.param(parameters[part.parameterIndex])
|
|
27
34
|
);
|
|
28
|
-
const result = await
|
|
35
|
+
const result = await queryable.execute(drizzleOrm.sql.join(chunks));
|
|
29
36
|
return result.rows;
|
|
30
37
|
}
|
|
31
|
-
};
|
|
38
|
+
});
|
|
32
39
|
}
|
|
33
40
|
|
|
34
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 {
|
|
2
|
+
import { PostgresExecutor } from './index.cjs';
|
|
3
3
|
|
|
4
4
|
/** What a Drizzle database and a Drizzle transaction have in common. */
|
|
5
5
|
interface DrizzleQueryable {
|
|
@@ -17,4 +17,5 @@ interface DrizzleLike extends DrizzleQueryable {
|
|
|
17
17
|
*/
|
|
18
18
|
declare function createDrizzleExecutor(database: DrizzleLike): PostgresExecutor<DrizzleQueryable>;
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export { createDrizzleExecutor };
|
|
21
|
+
export type { DrizzleLike, DrizzleQueryable };
|
package/dist/drizzle.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SQL } from 'drizzle-orm';
|
|
2
|
-
import {
|
|
2
|
+
import { PostgresExecutor } from './index.js';
|
|
3
3
|
|
|
4
4
|
/** What a Drizzle database and a Drizzle transaction have in common. */
|
|
5
5
|
interface DrizzleQueryable {
|
|
@@ -17,4 +17,5 @@ interface DrizzleLike extends DrizzleQueryable {
|
|
|
17
17
|
*/
|
|
18
18
|
declare function createDrizzleExecutor(database: DrizzleLike): PostgresExecutor<DrizzleQueryable>;
|
|
19
19
|
|
|
20
|
-
export {
|
|
20
|
+
export { createDrizzleExecutor };
|
|
21
|
+
export type { DrizzleLike, DrizzleQueryable };
|
package/dist/drizzle.js
CHANGED
|
@@ -1,18 +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
|
-
|
|
8
|
-
async query(sql$1, parameters, transaction) {
|
|
9
|
+
async run(queryable, { sql: sql$1, parameters }) {
|
|
9
10
|
const chunks = splitPositionalSql(sql$1).map(
|
|
10
11
|
(part) => typeof part === "string" ? sql.raw(part) : sql.param(parameters[part.parameterIndex])
|
|
11
12
|
);
|
|
12
|
-
const result = await
|
|
13
|
+
const result = await queryable.execute(sql.join(chunks));
|
|
13
14
|
return result.rows;
|
|
14
15
|
}
|
|
15
|
-
};
|
|
16
|
+
});
|
|
16
17
|
}
|
|
17
18
|
|
|
18
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"]}
|