okmodel 0.6.0 → 0.8.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 +100 -1131
- package/dist/adapters/capabilities.d.ts +35 -0
- package/dist/adapters/failure.d.ts +13 -2
- package/dist/adapters/lazy-errors.d.ts +22 -0
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +54 -3
- package/dist/adapters/pg/bunsql.d.ts +15 -2
- package/dist/adapters/pg/cursor.d.ts +17 -0
- package/dist/adapters/pg/neon-extra.d.ts +18 -0
- package/dist/adapters/pg/neon.d.ts +104 -0
- package/dist/adapters/pg/no-inflight-timeout.d.ts +11 -8
- package/dist/adapters/pg/nodepostgres-extra.d.ts +22 -1
- package/dist/adapters/pg/nodepostgres.d.ts +12 -0
- package/dist/adapters/pg/pglite-wire.d.ts +24 -0
- package/dist/adapters/pg/pglite.d.ts +10 -0
- package/dist/adapters/pg/postgres-extra.d.ts +27 -11
- package/dist/adapters/pg/reserved.d.ts +42 -0
- package/dist/adapters/pg/session.d.ts +0 -18
- package/dist/contracts/connection.d.ts +7 -6
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/floor.d.ts +68 -0
- package/dist/dialects/pg/fn/index.d.ts +39 -1
- package/dist/dialects/pg/fn/index.js +118 -26
- package/dist/dialects/pg/index.d.ts +8 -1
- package/dist/dialects/pg/index.js +435 -170
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/keys.d.ts +11 -8
- package/dist/dialects/pg/model.d.ts +40 -0
- package/dist/dialects/pg/morph.d.ts +43 -0
- package/dist/dialects/pg/operator-fit.d.ts +2 -2
- package/dist/dialects/pg/operators.d.ts +14 -7
- package/dist/dialects/pg/ops/bucket.d.ts +65 -0
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/inc.d.ts +2 -2
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- package/dist/dialects/pg/ops/matches.d.ts +9 -12
- package/dist/dialects/pg/ops/relevance.d.ts +13 -0
- package/dist/dialects/pg/ops/search-query.d.ts +22 -0
- package/dist/dialects/pg/ops/window.d.ts +103 -0
- package/dist/dialects/pg/preset.d.ts +1 -1
- package/dist/dialects/pg/relations.d.ts +100 -3
- package/dist/dialects/pg/schema.d.ts +31 -3
- package/dist/dialects/pg/view/client.d.ts +14 -6
- package/dist/dialects/pg/view/index.d.ts +73 -1
- package/dist/dialects/pg/view/index.js +156 -5
- package/dist/dialects/pg/view/scratch.d.ts +8 -5
- package/dist/runtime/aggregate.d.ts +8 -2
- package/dist/runtime/bucket-group.d.ts +70 -0
- package/dist/runtime/conflict.d.ts +22 -4
- package/dist/runtime/include.d.ts +0 -8
- package/dist/runtime/inflight.d.ts +1 -1
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/page.d.ts +4 -1
- package/dist/runtime/pg/bun.js +12 -6
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +5 -5
- package/dist/runtime/pg/pglite.d.ts +1 -0
- package/dist/runtime/pg/pglite.js +9 -9
- package/dist/runtime/pg/postgresjs.js +5 -5
- package/dist/runtime/plan.d.ts +95 -5
- package/dist/runtime/read-stream.d.ts +13 -16
- package/dist/runtime/result-name.d.ts +17 -0
- package/dist/runtime/server-check.d.ts +3 -3
- package/dist/runtime/sort-bind.d.ts +21 -0
- package/dist/runtime/sort.d.ts +56 -0
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/sync.d.ts +70 -0
- package/dist/runtime/tenancy/index.js +15 -13
- package/dist/runtime/text-search.d.ts +20 -0
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.d.ts +80 -0
- package/dist/runtime/traits/index.js +184 -21
- package/dist/runtime/tree.d.ts +38 -0
- package/dist/runtime/types.d.ts +232 -22
- package/dist/runtime/validate/index.js +4 -4
- package/dist/runtime/version.d.ts +39 -0
- package/dist/runtime/window.d.ts +21 -0
- package/dist/runtime/write.d.ts +54 -2
- package/dist/shared/{929h19xp.js → 0wrea3jq.js} +141 -13
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{1z04fa85.js → 14x60fbf.js} +12 -57
- package/dist/shared/{ek2wt2dz.js → 16kvjebh.js} +4 -4
- package/dist/shared/{wynzeggs.js → 195pzzzz.js} +8 -8
- package/dist/shared/1d9q9cv2.js +312 -0
- package/dist/shared/2c13q96h.js +18 -0
- package/dist/shared/{b4v57v3x.js → 2d3xq4ps.js} +2 -2
- package/dist/shared/{1f0xa3cb.js → 3449rcae.js} +5 -5
- package/dist/shared/{wkme6tep.js → 35q0n9tz.js} +8 -16
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/3t6kw83m.js +249 -0
- package/dist/shared/{5j36z8dn.js → 4m6hskg8.js} +39 -70
- package/dist/shared/{n076ydsc.js → 4vbf83xx.js} +69 -28
- package/dist/shared/{vmfkhszw.js → 63f4ksbz.js} +33 -26
- package/dist/shared/{c58secgj.js → 63qtkrca.js} +38 -4
- package/dist/shared/6m78c8ss.js +6 -0
- package/dist/shared/{x3jc53kg.js → 760ppr76.js} +15 -7
- package/dist/shared/7ghwamrf.js +40 -0
- package/dist/shared/7kms6fvj.js +20 -0
- package/dist/shared/7n7ddwt4.js +6 -0
- package/dist/shared/9a4ae4p8.js +31 -0
- package/dist/shared/{hazqqecq.js → 9dr2qnx7.js} +63 -34
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/a62rb2da.js +13 -0
- package/dist/shared/{cgbamx3e.js → ae4j5f42.js} +23 -4
- package/dist/shared/agsfb86s.js +233 -0
- package/dist/shared/{8x72s86k.js → b6d6p0zc.js} +13 -7
- package/dist/shared/{ag4c7516.js → b76b8d95.js} +2 -2
- package/dist/shared/{j60w0dvr.js → bah9nbg3.js} +58 -38
- package/dist/shared/bnby0esn.js +10 -0
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{2cg3wnxc.js → bxas03mq.js} +608 -141
- package/dist/shared/{31vm914h.js → cm3w0ywp.js} +15 -16
- package/dist/shared/{gwn6v667.js → cnkky55j.js} +25 -14
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{ttmg09vd.js → dpc2r7rb.js} +8 -8
- package/dist/shared/dzj09cye.js +10 -0
- package/dist/shared/{sbdme3vy.js → e8zyaqvj.js} +60 -10
- package/dist/shared/{2jd1sn0e.js → ecn8mfdq.js} +6 -6
- package/dist/shared/exn3sd90.js +359 -0
- package/dist/shared/{t3g0k88x.js → f4jy1j7x.js} +39 -22
- package/dist/shared/{y2t3jktd.js → fjpnhqan.js} +20 -13
- package/dist/shared/g5yc06ka.js +272 -0
- package/dist/shared/ga9j92qj.js +25 -0
- package/dist/shared/{3fqwmr09.js → hfqmpasr.js} +6 -6
- package/dist/shared/{wt5rzv1h.js → hm5f8jby.js} +7 -7
- package/dist/shared/{ys0xzyaj.js → hqpxf4a4.js} +224 -19
- package/dist/shared/jebgrkeq.js +179 -0
- package/dist/shared/{09p049xa.js → jp36k7dp.js} +44 -16
- package/dist/shared/jx2m62cs.js +96 -0
- package/dist/shared/{r11n8grd.js → k86n8vq3.js} +7 -4
- package/dist/shared/{2z7wv5tj.js → kgwp4jdd.js} +56 -35
- package/dist/shared/{knmes2kh.js → kj9d8maq.js} +1 -1
- package/dist/shared/{g90m9b0g.js → m4xff2a6.js} +6 -5
- package/dist/shared/{r6nwkxnt.js → m7n9h2a5.js} +4 -4
- package/dist/shared/mfedzr74.js +145 -0
- package/dist/shared/{f0f1n281.js → mkrn359n.js} +60 -11
- package/dist/shared/{p248q79y.js → mnvjvqyp.js} +10 -10
- package/dist/shared/{672t5vym.js → mss6ctgv.js} +2 -2
- package/dist/shared/{4az561fn.js → mtw6jz76.js} +8 -23
- package/dist/shared/n05z9nwz.js +313 -0
- package/dist/shared/{pjr6xrm5.js → n0jmpgj1.js} +20 -17
- package/dist/shared/{p6bjzq9q.js → n41w4fbz.js} +14 -6
- package/dist/shared/{b3awxn7h.js → n454kcnw.js} +1 -1
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/nbw1z4yd.js +18 -0
- package/dist/shared/needfe47.js +66 -0
- package/dist/shared/{1nw1f3vs.js → njga14v4.js} +9 -9
- package/dist/shared/{5yv4k6a6.js → nmnsgj7x.js} +145 -3
- package/dist/shared/{vjpnzwjz.js → p3xbdcvt.js} +14 -18
- package/dist/shared/p5nh3r8q.js +622 -0
- package/dist/shared/{nx9hh281.js → pan0370z.js} +13 -12
- package/dist/shared/q0cqt2sp.js +12 -0
- package/dist/shared/qd9hhd8f.js +37 -0
- package/dist/shared/{mb2ycs1p.js → qfw14tna.js} +15 -15
- package/dist/shared/{9s0ypp87.js → sjk86yrx.js} +1 -1
- package/dist/shared/th3be82n.js +208 -0
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{5d8t84hg.js → v1wad97q.js} +14 -14
- package/dist/shared/{x72jb7ad.js → v8g1vgv8.js} +1 -1
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{q3j1tq7a.js → wcrheftc.js} +148 -23
- package/dist/shared/wvdjznah.js +213 -0
- package/dist/shared/wz2a78mp.js +8 -0
- package/dist/shared/xfhe73sb.js +436 -0
- package/dist/shared/{r1fdd0f6.js → z581d7ny.js} +5 -2
- package/dist/shared/{8etn7d8w.js → z7s6fpxv.js} +1 -1
- package/dist/shared/{32cnm7kn.js → zbqbmmrp.js} +76 -40
- package/dist/shared/{n7mcc1gk.js → zchaghkf.js} +4 -3
- package/dist/shared/{xq0mvhts.js → zgex00fd.js} +6 -6
- package/dist/shared/{nsva2a6b.js → znm0bpp5.js} +3 -0
- package/dist/shared/zq1he88x.js +155 -0
- package/dist/tooling/cli.js +26 -13
- package/dist/tooling/driver-run.js +4971 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/migrate/commands.d.ts +2 -2
- package/dist/tooling/migrate/engine.d.ts +3 -2
- package/dist/tooling/migrate/index.js +9 -9
- package/dist/tooling/migrate/project.d.ts +3 -0
- package/dist/tooling/shared/03k6res6.js +210 -0
- package/dist/tooling/shared/08kemxjd.js +10 -0
- package/dist/tooling/shared/2revefqt.js +209 -0
- package/dist/tooling/shared/2wtvc7rw.js +1425 -0
- package/dist/tooling/shared/345tbc2k.js +16 -0
- package/dist/tooling/shared/3m1hkg7z.js +344 -0
- package/dist/tooling/shared/3rrw5w8f.js +81 -0
- package/dist/tooling/shared/3tq8pnb8.js +131 -0
- package/dist/tooling/shared/417zdsk7.js +194 -0
- package/dist/tooling/shared/4d2w25vw.js +40 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/5bvw2nev.js +12 -0
- package/dist/tooling/shared/6nyfyw70.js +231 -0
- package/dist/tooling/shared/72fyg4zv.js +160 -0
- package/dist/tooling/shared/733a1tq3.js +38 -0
- package/dist/tooling/shared/7ae7rjmn.js +20 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/8sqrsw3s.js +49 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9kazs5p6.js +195 -0
- package/dist/tooling/shared/9xzm7hjg.js +38 -0
- package/dist/tooling/shared/a6pp9d12.js +49 -0
- package/dist/tooling/shared/a7q7t4n3.js +22 -0
- package/dist/tooling/shared/aftb2mwr.js +18 -0
- package/dist/tooling/shared/bz2dqhab.js +311 -0
- package/dist/tooling/shared/cmptmb4f.js +12 -0
- package/dist/tooling/shared/ddjtfgnx.js +177 -0
- package/dist/tooling/shared/djydjpqt.js +261 -0
- package/dist/tooling/shared/dw08f3m8.js +9 -0
- package/dist/tooling/shared/dy672fz6.js +16 -0
- package/dist/tooling/shared/dzx85q70.js +66 -0
- package/dist/tooling/shared/ec71zqgt.js +270 -0
- package/dist/{shared/d5azex6s.js → tooling/shared/ep8zh3bk.js} +1 -1
- package/dist/tooling/shared/f9mphxej.js +3789 -0
- package/dist/tooling/shared/fb9k2qwd.js +89 -0
- package/dist/tooling/shared/g9ad4n80.js +211 -0
- package/dist/tooling/shared/gfvtj6d0.js +94 -0
- package/dist/tooling/shared/gmcf9cxf.js +294 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j9t5s12a.js +7 -0
- package/dist/tooling/shared/jne7b93p.js +42 -0
- package/dist/tooling/shared/ma2340rx.js +118 -0
- package/dist/tooling/shared/mtrqn2hn.js +505 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nf7jmhfa.js +20 -0
- package/dist/tooling/shared/p7f08ktn.js +332 -0
- package/dist/tooling/shared/ppnnnvj8.js +13 -0
- package/dist/tooling/shared/pqy21k24.js +312 -0
- package/dist/tooling/shared/pw8fgahx.js +69 -0
- package/dist/tooling/shared/pwsytxm5.js +17 -0
- package/dist/tooling/shared/rf83gr2d.js +94 -0
- package/dist/tooling/shared/rq5kk8j6.js +401 -0
- package/dist/tooling/shared/rs1jb051.js +12 -0
- package/dist/tooling/shared/smn6kz1p.js +157 -0
- package/dist/tooling/shared/spk1jg3r.js +1696 -0
- package/dist/tooling/shared/tn8gay14.js +143 -0
- package/dist/tooling/shared/vraj6d74.js +42 -0
- package/dist/tooling/shared/vs0t6qt8.js +64 -0
- package/dist/tooling/shared/vx86qjv8.js +150 -0
- package/dist/tooling/shared/w7qe8sj1.js +140 -0
- package/dist/tooling/shared/wt7j7nf6.js +15 -0
- package/dist/tooling/shared/wwnekq5n.js +6 -0
- package/dist/tooling/shared/xhrnjch9.js +185 -0
- package/dist/tooling/shared/xjs6zqtc.js +190 -0
- package/dist/tooling/shared/y031jct9.js +16 -0
- package/dist/tooling/shared/y5656f0e.js +233 -0
- package/dist/tooling/shared/yfr8hzhm.js +604 -0
- package/dist/tooling/shared/yk9mp7vb.js +250 -0
- package/dist/tooling/shared/yw30vnq2.js +139 -0
- package/dist/tooling/shared/z8d7ptht.js +618 -0
- package/dist/tooling/shared/zhwnfyb2.js +9 -0
- package/dist/tooling/shared/zvnhh1n0.js +198 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +17 -3
- package/dist/shared/3qnhc7w5.js +0 -38
- package/dist/shared/7m88x3e9.js +0 -45
- package/dist/shared/8dqhth8c.js +0 -12
- package/dist/shared/j3rkk835.js +0 -99
- package/dist/shared/k68eedmy.js +0 -85
- package/dist/shared/venqrjna.js +0 -216
- package/dist/shared/wxr8cwns.js +0 -6
- package/dist/shared/y34a8714.js +0 -150
- package/dist/shared/zm0mafk4.js +0 -92
- package/dist/shared/zy8r7qvz.js +0 -116
- package/dist/shared/{ywr8hmey.js → 606g0nbf.js} +3 -3
- package/dist/shared/{rpycarcr.js → gcefca6p.js} +4 -4
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* OKM11xx for a driver that lacks a flag: OKM1110 is the engine-version gate,
|
|
6
6
|
* and OKM1801 is a dialect mismatch. This module does not invent a code and
|
|
7
7
|
* does not throw for a missing flag.
|
|
8
|
+
*
|
|
9
|
+
* `stream` means the driver can open a server cursor. `.stream()` does not
|
|
10
|
+
* read it. That method walks keyset batches on every driver.
|
|
8
11
|
*/
|
|
9
12
|
import type { DriverCapabilities } from "../contracts/driver.js";
|
|
10
13
|
/** Capability names a caller can read. */
|
|
@@ -75,6 +78,38 @@ export declare const BUNSQL_CAPABILITIES: {
|
|
|
75
78
|
readonly prepared: "unnamed";
|
|
76
79
|
readonly describe: false;
|
|
77
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Neon WebSocket pool execution flags.
|
|
83
|
+
*
|
|
84
|
+
* Interactive transactions pass on a direct connection. `stream`, `listen`,
|
|
85
|
+
* `cancel`, and `describe` stay false: a server cursor, `LISTEN`, and a
|
|
86
|
+
* side-channel cancel are session features the pooler does not keep, and the
|
|
87
|
+
* client has no describe API. Statements use the unnamed protocol.
|
|
88
|
+
* `prepared: "named"` is not for a transaction-mode pooler.
|
|
89
|
+
*/
|
|
90
|
+
export declare const NEON_WEBSOCKET_CAPABILITIES: {
|
|
91
|
+
readonly transactions: "interactive";
|
|
92
|
+
readonly stream: false;
|
|
93
|
+
readonly listen: false;
|
|
94
|
+
readonly cancel: false;
|
|
95
|
+
readonly prepared: "unnamed";
|
|
96
|
+
readonly describe: false;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Neon HTTP execution flags.
|
|
100
|
+
*
|
|
101
|
+
* One request is one statement. `sql.transaction` is the atomic batch.
|
|
102
|
+
* There is no interactive `tx()`, no `LISTEN`, no server cursor, and no
|
|
103
|
+
* cancel of a statement the server has already started.
|
|
104
|
+
*/
|
|
105
|
+
export declare const NEON_HTTP_CAPABILITIES: {
|
|
106
|
+
readonly transactions: "batch";
|
|
107
|
+
readonly stream: false;
|
|
108
|
+
readonly listen: false;
|
|
109
|
+
readonly cancel: false;
|
|
110
|
+
readonly prepared: "none";
|
|
111
|
+
readonly describe: false;
|
|
112
|
+
};
|
|
78
113
|
/**
|
|
79
114
|
* Reads one capability flag.
|
|
80
115
|
*
|
|
@@ -13,10 +13,21 @@ export declare function driverErrors(): Promise<ErrorModule>;
|
|
|
13
13
|
/**
|
|
14
14
|
* Rejects with a closed-pool {@link import("./error.js").DriverError}.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
16
|
+
* The text and SQLSTATE `08006` load with the lazy error module. Classification
|
|
17
|
+
* reads the SQLSTATE. The message is "The pool is closed."
|
|
18
|
+
*
|
|
19
|
+
* @returns A rejected promise
|
|
20
|
+
*/
|
|
21
|
+
export declare function rejectClosed(): Promise<never>;
|
|
22
|
+
/**
|
|
23
|
+
* Rejects with OKM1120 when a driver cannot cancel a positive timeout.
|
|
24
|
+
*
|
|
25
|
+
* The message stays `timeout`. Kind stays `invalid`. Bun.sql, PGlite, and Neon call
|
|
26
|
+
* this. Other drivers do not, so their connect graphs omit it.
|
|
27
|
+
*
|
|
17
28
|
* @returns A rejected promise
|
|
18
29
|
*/
|
|
19
|
-
export declare function
|
|
30
|
+
export declare function rejectUncancellable(): Promise<never>;
|
|
20
31
|
/**
|
|
21
32
|
* Rejects with kind `cancelled`.
|
|
22
33
|
*
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error text a connect entry does not need until a call fails.
|
|
3
|
+
*
|
|
4
|
+
* Loaded on the first closed pool or on a positive `timeout` for a driver
|
|
5
|
+
* that cannot cancel. A successful execute does not import this module.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* OKM1120 for a positive `timeout` on Bun.sql or PGlite.
|
|
9
|
+
*
|
|
10
|
+
* Kind stays `invalid`. The message stays `timeout` (D224, D239).
|
|
11
|
+
*
|
|
12
|
+
* @returns A rejected promise
|
|
13
|
+
*/
|
|
14
|
+
export declare function refused(): Promise<never>;
|
|
15
|
+
/**
|
|
16
|
+
* A pool that has already been closed.
|
|
17
|
+
*
|
|
18
|
+
* The message is for people. Classification reads SQLSTATE `08006`.
|
|
19
|
+
*
|
|
20
|
+
* @returns A rejected promise
|
|
21
|
+
*/
|
|
22
|
+
export declare function closed(): Promise<never>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The slice of Bun.sql this adapter uses.
|
|
3
|
+
*
|
|
4
|
+
* `bun` is the runtime, not an npm package, and it ships no types. The
|
|
5
|
+
* published declarations name these types instead of importing `bun`, so a
|
|
6
|
+
* consumer can typecheck `okmodel/pg/bun` without `bun-types`.
|
|
7
|
+
*/
|
|
8
|
+
/** A pending query. `raw()` asks for rows as arrays. */
|
|
9
|
+
export interface SQLQuery extends Promise<unknown> {
|
|
10
|
+
/** Rows as arrays instead of objects. */
|
|
11
|
+
raw(): SQLQuery;
|
|
12
|
+
}
|
|
13
|
+
/** One pooled Bun.sql client. */
|
|
14
|
+
export interface SQL {
|
|
15
|
+
/**
|
|
16
|
+
* Runs a statement.
|
|
17
|
+
*
|
|
18
|
+
* @param text - SQL text
|
|
19
|
+
* @param values - Positional parameters
|
|
20
|
+
*/
|
|
21
|
+
unsafe(text: string, values?: readonly unknown[]): SQLQuery;
|
|
22
|
+
/**
|
|
23
|
+
* Checks out one connection.
|
|
24
|
+
*
|
|
25
|
+
* @param options - `signal` aborts the wait
|
|
26
|
+
*/
|
|
27
|
+
reserve(options?: {
|
|
28
|
+
readonly signal?: AbortSignal;
|
|
29
|
+
}): Promise<ReservedSQL>;
|
|
30
|
+
/** Closes the pool. */
|
|
31
|
+
close(): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Subscribes to one `LISTEN` channel.
|
|
34
|
+
*
|
|
35
|
+
* @param channel - Channel name
|
|
36
|
+
* @param onnotify - Payload callback
|
|
37
|
+
*/
|
|
38
|
+
listen(channel: string, onnotify: (payload: string) => void): Promise<SQLListen>;
|
|
39
|
+
}
|
|
40
|
+
/** A `LISTEN` registration. */
|
|
41
|
+
export interface SQLListen {
|
|
42
|
+
/** Drops this registration. */
|
|
43
|
+
unlisten(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* One connection reserved from {@link SQL.reserve}.
|
|
47
|
+
*
|
|
48
|
+
* `release` returns it to the pool.
|
|
49
|
+
*/
|
|
50
|
+
export interface ReservedSQL extends SQL {
|
|
51
|
+
/** Returns the connection to the pool. */
|
|
52
|
+
release(): void;
|
|
53
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reserved connections for Bun.sql.
|
|
3
3
|
*
|
|
4
|
-
* Loaded on the first reserve, batch, or
|
|
4
|
+
* Loaded on the first reserve, batch, stream, or dead connection. A read that
|
|
5
|
+
* succeeds does not use it.
|
|
5
6
|
*/
|
|
6
|
-
import type {
|
|
7
|
+
import type { ReservedSQL, SQL } from "./bun-sql.js";
|
|
8
|
+
import type { DriverConnection, WireValue } from "../../contracts/driver.js";
|
|
7
9
|
import { type HeldPool } from "./bunsql.js";
|
|
8
10
|
/**
|
|
9
11
|
* Checks out one connection and clears it on release.
|
|
@@ -14,4 +16,53 @@ import { type HeldPool } from "./bunsql.js";
|
|
|
14
16
|
* @param held - The pool and its counters
|
|
15
17
|
* @returns A connection the caller must release
|
|
16
18
|
*/
|
|
17
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Drops a dead pooled socket, then runs `again` once when that is safe.
|
|
21
|
+
*
|
|
22
|
+
* A `57P01` or a socket Bun has already closed is evicted before another
|
|
23
|
+
* statement can take it. A client read is tried once more when `depth` is 0.
|
|
24
|
+
* A raw pool retries only when the socket had already closed, or Bun rejected
|
|
25
|
+
* the statement before the server saw it, so a query killed while it was
|
|
26
|
+
* running is not started again. `again` does not pass through `recover`.
|
|
27
|
+
*
|
|
28
|
+
* @param sql - The pool
|
|
29
|
+
* @param error - The failure from the first attempt
|
|
30
|
+
* @param text - Statement text, used to decide the retry
|
|
31
|
+
* @param depth - Open transaction depth. Above zero, an earlier command was sent
|
|
32
|
+
* @param clientRead - The pool was opened for a client, which retries a read once
|
|
33
|
+
* @param closedDuring - `onclose` ran after this statement was sent
|
|
34
|
+
* @param again - The same statement, on whatever connection the pool hands out next
|
|
35
|
+
* @returns The retried result, or a rejection of `error`
|
|
36
|
+
*/
|
|
37
|
+
export declare function recover<T>(sql: SQL, error: unknown, text: string, depth: number, clientRead: boolean, closedDuring: boolean, again: () => Promise<T>): Promise<T>;
|
|
38
|
+
/**
|
|
39
|
+
* Spends a closed socket before the caller's statement is sent.
|
|
40
|
+
*
|
|
41
|
+
* @param sql - The pool
|
|
42
|
+
*/
|
|
43
|
+
export declare function drainClosed(sql: SQL): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Subscribes on one pooled connection.
|
|
46
|
+
*
|
|
47
|
+
* @param sql - The pool
|
|
48
|
+
* @param parked - Reserved handles to put back first
|
|
49
|
+
* @param closed - The pool is closed
|
|
50
|
+
* @param channel - Notify channel
|
|
51
|
+
* @param onNotify - Payload callback
|
|
52
|
+
* @returns Stops the subscription
|
|
53
|
+
*/
|
|
54
|
+
export declare function listen(sql: SQL, parked: ReservedSQL[], closed: boolean, channel: string, onNotify: (payload: string) => void): Promise<() => Promise<void>>;
|
|
55
|
+
export declare function checkout(held: HeldPool): Promise<DriverConnection & {
|
|
56
|
+
evict(): void;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Yields cursor chunks from one checked-out Bun.sql connection.
|
|
60
|
+
*
|
|
61
|
+
* @param checkout - Reserves the connection
|
|
62
|
+
* @param text - Query to stream
|
|
63
|
+
* @param params - Wire parameters
|
|
64
|
+
* @returns Chunks of wire rows
|
|
65
|
+
*/
|
|
66
|
+
export declare function streamRows(checkout: () => Promise<DriverConnection & {
|
|
67
|
+
evict?: () => void;
|
|
68
|
+
}>, text: string, params: readonly WireValue[] | undefined): AsyncIterable<readonly (readonly WireValue[])[]>;
|
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
* finished script exits without `close()`. `Query.cancel()` does not abort
|
|
10
10
|
* the backend, so `cancel` is false. Server notices are not surfaced.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import type { ReservedSQL, SQL } from "./bun-sql.js";
|
|
13
13
|
import type { DriverPool, DriverPoolConfig, WireValue } from "../../contracts/driver.js";
|
|
14
|
+
import { DriverError } from "../error.js";
|
|
14
15
|
import { noticeBuffer, type WireQuery } from "./session.js";
|
|
15
16
|
export { BUNSQL_CAPABILITIES as capabilities, hasCapability, readCapability, } from "../capabilities.js";
|
|
16
|
-
export { DriverError }
|
|
17
|
+
export { DriverError };
|
|
17
18
|
/** TLS values Bun.sql accepts that this adapter forwards. */
|
|
18
19
|
export type BunSqlTls = boolean | "disable" | "allow" | "prefer" | "require" | "verify-ca" | "verify-full";
|
|
19
20
|
/** Options for {@link open}. */
|
|
@@ -40,7 +41,19 @@ export type HeldPool = {
|
|
|
40
41
|
readonly counters: Counters;
|
|
41
42
|
readonly notices: ReturnType<typeof noticeBuffer>;
|
|
42
43
|
readonly isClosed: () => boolean;
|
|
44
|
+
/** Sockets this pool has closed. The count never returns to zero. */
|
|
45
|
+
readonly closures: () => number;
|
|
43
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Marks a pool opened for a client.
|
|
49
|
+
*
|
|
50
|
+
* A client read that finds a dead socket is tried once. A pool from raw
|
|
51
|
+
* {@link open} is not marked, so a statement the server killed while it was
|
|
52
|
+
* running is not started again.
|
|
53
|
+
*
|
|
54
|
+
* @param pool - The pool `connect` just opened
|
|
55
|
+
*/
|
|
56
|
+
export declare function markClientPool(pool: DriverPool): void;
|
|
44
57
|
/** Pool occupancy. */
|
|
45
58
|
export type Counters = {
|
|
46
59
|
reserved: number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side cursor for drivers that stream through a checked-out connection.
|
|
3
|
+
*
|
|
4
|
+
* Loaded with the stream chunk. A read does not import this.
|
|
5
|
+
*/
|
|
6
|
+
import type { ExecuteResult, WireValue } from "../../contracts/driver.js";
|
|
7
|
+
/**
|
|
8
|
+
* Yields cursor chunks from one connection that is already checked out.
|
|
9
|
+
*
|
|
10
|
+
* The cursor is session-local. `ROLLBACK` in the end drops it.
|
|
11
|
+
*
|
|
12
|
+
* @param run - Executes on the checked-out connection
|
|
13
|
+
* @param text - Query to stream
|
|
14
|
+
* @param params - Wire parameters
|
|
15
|
+
* @returns Chunks of wire rows
|
|
16
|
+
*/
|
|
17
|
+
export declare function cursorStream(run: (text: string, params?: readonly WireValue[]) => Promise<ExecuteResult>, text: string, params: readonly WireValue[] | undefined): AsyncIterable<readonly (readonly WireValue[])[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reserved connections for the Neon WebSocket pool.
|
|
3
|
+
*
|
|
4
|
+
* Loaded on the first reserve or batch. A read does not use it.
|
|
5
|
+
*/
|
|
6
|
+
import type { DriverConnection } from "../../contracts/driver.js";
|
|
7
|
+
import { type HeldPool } from "./neon.js";
|
|
8
|
+
/**
|
|
9
|
+
* Checks out one client and clears it on release.
|
|
10
|
+
*
|
|
11
|
+
* A client whose connection is gone is destroyed on release, and nothing more
|
|
12
|
+
* is sent to it. A checked-out client has no pool error listener, so one is
|
|
13
|
+
* set here: without it a dropped socket is an uncaught `error` event.
|
|
14
|
+
*
|
|
15
|
+
* @param held - The pool and its counters
|
|
16
|
+
* @returns A connection the caller must release
|
|
17
|
+
*/
|
|
18
|
+
export declare function checkout(held: HeldPool): Promise<DriverConnection>;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neon adapter (`okmodel/pg/neon`).
|
|
3
|
+
*
|
|
4
|
+
* `@neondatabase/serverless` is an optional peer. This module is the only
|
|
5
|
+
* place that imports it. `mode: "websocket"` (the default) is a pooled
|
|
6
|
+
* WebSocket client with interactive transactions. `mode: "http"` is one HTTP
|
|
7
|
+
* request per statement, and `batch` is the driver's non-interactive
|
|
8
|
+
* transaction. A positive `timeout` is refused: neither mode aborts a
|
|
9
|
+
* statement the server has already started.
|
|
10
|
+
*
|
|
11
|
+
* The first WebSocket `open` sets `webSocketConstructor` only when it is
|
|
12
|
+
* still unset, so a caller can install one first. A transaction-mode pooler
|
|
13
|
+
* does not promise session state. One small compute can reuse a backend, so
|
|
14
|
+
* a custom `SET`, `LISTEN`, or a prepared statement may still be visible.
|
|
15
|
+
*/
|
|
16
|
+
import { Pool, type PoolClient } from "@neondatabase/serverless";
|
|
17
|
+
import type { DriverPool, DriverPoolConfig, WireValue } from "../../contracts/driver.js";
|
|
18
|
+
import { noticeBuffer, type WireQuery } from "./session.js";
|
|
19
|
+
export { NEON_WEBSOCKET_CAPABILITIES as capabilities, NEON_HTTP_CAPABILITIES as httpCapabilities, hasCapability, readCapability, } from "../capabilities.js";
|
|
20
|
+
export { DriverError } from "../error.js";
|
|
21
|
+
/** How {@link open} talks to Neon. */
|
|
22
|
+
export type NeonMode = "websocket" | "http";
|
|
23
|
+
/** Options for {@link open}. */
|
|
24
|
+
export type NeonConfig = DriverPoolConfig & {
|
|
25
|
+
/** Connection URL for this endpoint. */
|
|
26
|
+
readonly url: string;
|
|
27
|
+
/**
|
|
28
|
+
* `websocket` is a pooled WebSocket client. `http` is one-shot HTTP.
|
|
29
|
+
*
|
|
30
|
+
* Omitted means `websocket`.
|
|
31
|
+
*/
|
|
32
|
+
readonly mode?: NeonMode;
|
|
33
|
+
/**
|
|
34
|
+
* Named prepared statements, or the unnamed protocol.
|
|
35
|
+
*
|
|
36
|
+
* Unnamed is the default. It stays valid behind a pooler in transaction mode.
|
|
37
|
+
* `prepared: "named"` is not for transaction-mode poolers. HTTP ignores it.
|
|
38
|
+
*/
|
|
39
|
+
readonly prepared?: "named" | "unnamed";
|
|
40
|
+
/** Session search path for every WebSocket connection in the pool. */
|
|
41
|
+
readonly searchPath?: string;
|
|
42
|
+
};
|
|
43
|
+
/** Pool occupancy. */
|
|
44
|
+
export type Counters = {
|
|
45
|
+
reserved: number;
|
|
46
|
+
busy: number;
|
|
47
|
+
reservedBusy: number;
|
|
48
|
+
waiting: number;
|
|
49
|
+
};
|
|
50
|
+
/** What a WebSocket checkout needs from the pool that opened it. */
|
|
51
|
+
export type HeldPool = {
|
|
52
|
+
readonly pool: Pool;
|
|
53
|
+
readonly acquireMs: number | undefined;
|
|
54
|
+
readonly counters: Counters;
|
|
55
|
+
readonly notices: ReturnType<typeof noticeBuffer>;
|
|
56
|
+
readonly named: boolean;
|
|
57
|
+
readonly isClosed: () => boolean;
|
|
58
|
+
};
|
|
59
|
+
/** A client that can run one array-mode statement. */
|
|
60
|
+
type Queryable = {
|
|
61
|
+
query(config: {
|
|
62
|
+
text: string;
|
|
63
|
+
values?: readonly WireValue[];
|
|
64
|
+
rowMode: "array";
|
|
65
|
+
types: typeof WIRE;
|
|
66
|
+
name?: string;
|
|
67
|
+
}): Promise<unknown>;
|
|
68
|
+
};
|
|
69
|
+
declare const WIRE: {
|
|
70
|
+
getTypeParser(): (value: string) => string;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Opens a Neon pool for one endpoint.
|
|
74
|
+
*
|
|
75
|
+
* WebSocket mode connects once before returning, so a later short acquire
|
|
76
|
+
* timeout measures the queue and not a cold start. HTTP mode does not open a
|
|
77
|
+
* socket.
|
|
78
|
+
*
|
|
79
|
+
* @param config - URL, mode, pool size, and acquire timeout
|
|
80
|
+
* @returns The pool
|
|
81
|
+
*/
|
|
82
|
+
export declare function open(config: NeonConfig): Promise<DriverPool>;
|
|
83
|
+
/**
|
|
84
|
+
* Checks out one WebSocket client.
|
|
85
|
+
*
|
|
86
|
+
* The wait uses `timeouts.acquire`. A timeout is OKM1846 and does not keep the
|
|
87
|
+
* client.
|
|
88
|
+
*
|
|
89
|
+
* @param pool - Neon pool
|
|
90
|
+
* @param acquireMs - Wait ceiling, when one was set
|
|
91
|
+
* @param counters - Pool occupancy
|
|
92
|
+
* @returns The client
|
|
93
|
+
*/
|
|
94
|
+
export declare function connectClient(pool: Pool, acquireMs: number | undefined, counters: Counters): Promise<PoolClient>;
|
|
95
|
+
/**
|
|
96
|
+
* Sends one statement and returns the driver's promise.
|
|
97
|
+
*
|
|
98
|
+
* @param runner - Pool or checked-out client
|
|
99
|
+
* @param text - SQL
|
|
100
|
+
* @param params - Wire parameters
|
|
101
|
+
* @param named - Use a named prepared statement
|
|
102
|
+
* @returns The pending result
|
|
103
|
+
*/
|
|
104
|
+
export declare function send(runner: Queryable, text: string, params: readonly WireValue[] | undefined, named: boolean): WireQuery;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Refusal for a driver that cannot cancel an in-flight statement (D224).
|
|
3
3
|
*
|
|
4
|
-
* Bun.sql
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Bun.sql, PGlite, and Neon refuse a positive `timeout`. The OKM1120 text loads with
|
|
5
|
+
* the lazy error module, so a connect entry does not carry it. Kind is
|
|
6
|
+
* `invalid`, which separates it from kind `timeout`. `timeout: 0` still fails
|
|
7
|
+
* immediately as kind `timeout`. `signal` is unchanged. postgres.js and
|
|
8
|
+
* node-postgres do not import this.
|
|
9
9
|
*/
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Returns a rejected OKM1120 when `timeout` is a positive number.
|
|
12
12
|
*
|
|
13
|
-
*
|
|
13
|
+
* Absent, and a non-positive timeout, return `undefined` so the caller runs.
|
|
14
|
+
*
|
|
15
|
+
* @param options - Per-call options
|
|
16
|
+
* @returns A rejected promise, or `undefined` when the call may run
|
|
14
17
|
*/
|
|
15
18
|
export declare function noTimeout(options: {
|
|
16
19
|
readonly timeout?: number;
|
|
17
|
-
} | undefined):
|
|
20
|
+
} | undefined): Promise<never> | undefined;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Loaded on the first reserve, batch, or stream. A read does not use it.
|
|
5
5
|
*/
|
|
6
|
-
import type { DriverConnection } from "../../contracts/driver.js";
|
|
6
|
+
import type { DriverConnection, WireValue } from "../../contracts/driver.js";
|
|
7
7
|
import { type HeldPool } from "./nodepostgres.js";
|
|
8
8
|
/**
|
|
9
9
|
* Checks out one client and clears it on release.
|
|
@@ -16,3 +16,24 @@ import { type HeldPool } from "./nodepostgres.js";
|
|
|
16
16
|
* @returns A connection the caller must release
|
|
17
17
|
*/
|
|
18
18
|
export declare function checkout(held: HeldPool): Promise<DriverConnection>;
|
|
19
|
+
/**
|
|
20
|
+
* Listens on one checked-out client.
|
|
21
|
+
*
|
|
22
|
+
* The client has no pool error listener. One is set here so a dropped socket
|
|
23
|
+
* is not an uncaught `error` event.
|
|
24
|
+
*
|
|
25
|
+
* @param held - The pool and its counters
|
|
26
|
+
* @param channel - Notification channel
|
|
27
|
+
* @param onNotify - Called with each payload
|
|
28
|
+
* @returns Stops the listener
|
|
29
|
+
*/
|
|
30
|
+
export declare function listen(held: HeldPool, channel: string, onNotify: (payload: string) => void): Promise<() => Promise<void>>;
|
|
31
|
+
/**
|
|
32
|
+
* Yields cursor chunks from one checked-out client.
|
|
33
|
+
*
|
|
34
|
+
* @param checkout - Reserves the connection
|
|
35
|
+
* @param text - Query to stream
|
|
36
|
+
* @param params - Wire parameters
|
|
37
|
+
* @returns Chunks of wire rows
|
|
38
|
+
*/
|
|
39
|
+
export declare function streamRows(checkout: () => Promise<DriverConnection>, text: string, params: readonly WireValue[] | undefined): AsyncIterable<readonly (readonly WireValue[])[]>;
|
|
@@ -44,6 +44,18 @@ export type Counters = {
|
|
|
44
44
|
reservedBusy: number;
|
|
45
45
|
waiting: number;
|
|
46
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Attaches the one error listener a pool or a checked-out client can use.
|
|
49
|
+
*
|
|
50
|
+
* node-postgres types list `connect` and `notification` only. An idle pool
|
|
51
|
+
* client and a `LISTEN` client both emit `error` with no listener, and that
|
|
52
|
+
* is an uncaught exception. The default handler ignores it. The pool has
|
|
53
|
+
* already removed an idle client.
|
|
54
|
+
*
|
|
55
|
+
* @param source - Pool or client
|
|
56
|
+
* @param handle - What to do with the error
|
|
57
|
+
*/
|
|
58
|
+
export declare function armDriverError(source: object, handle?: () => void): void;
|
|
47
59
|
/**
|
|
48
60
|
* Opens a node-postgres pool for one endpoint.
|
|
49
61
|
*
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PGlite wire codecs, loaded from {@link import("./pglite.ts").open}.
|
|
3
|
+
*
|
|
4
|
+
* A JS number, bigint, or boolean is sent as wire text. An `08P01` from a
|
|
5
|
+
* bad parameter is a driver error. A lost connection stays `unavailable`.
|
|
6
|
+
*/
|
|
7
|
+
declare const parsers: Record<number, (value: string) => string>;
|
|
8
|
+
declare const serializers: Record<number, (value: unknown) => string>;
|
|
9
|
+
/** Identity parsers. The dialect owns parsing. */
|
|
10
|
+
export { parsers };
|
|
11
|
+
/** Wire-text serializers. Number, bigint, and boolean are text. */
|
|
12
|
+
export { serializers };
|
|
13
|
+
/**
|
|
14
|
+
* Maps a PGlite failure.
|
|
15
|
+
*
|
|
16
|
+
* `08P01` means the parameter did not fit the protocol message. The
|
|
17
|
+
* replacement carries the message and neither a SQLSTATE nor a cause, so the
|
|
18
|
+
* kind is `driver`. Any other failure, including a closed connection, is
|
|
19
|
+
* mapped unchanged.
|
|
20
|
+
*
|
|
21
|
+
* @param error - Caught value
|
|
22
|
+
* @returns A normalised driver error
|
|
23
|
+
*/
|
|
24
|
+
export declare function fail(error: unknown): Promise<unknown>;
|
|
@@ -19,3 +19,13 @@ export type PgliteConfig = DriverPoolConfig & {
|
|
|
19
19
|
* @returns The pool
|
|
20
20
|
*/
|
|
21
21
|
export declare function open(config?: PgliteConfig): Promise<DriverPool>;
|
|
22
|
+
/**
|
|
23
|
+
* A pool whose `close` marks this client only.
|
|
24
|
+
*
|
|
25
|
+
* The inner pool stays open. A later call fails as unavailable.
|
|
26
|
+
* The body stays this small: the PGlite incremental figure is 11,510, 500 under its gate.
|
|
27
|
+
*
|
|
28
|
+
* @param pool - The caller's pool
|
|
29
|
+
* @returns A pool the client owns
|
|
30
|
+
*/
|
|
31
|
+
export declare function seal(pool: DriverPool): DriverPool;
|
|
@@ -4,9 +4,14 @@
|
|
|
4
4
|
* Loaded on the first reserve, batch, describe, or stream.
|
|
5
5
|
*/
|
|
6
6
|
import type { Sql } from "postgres";
|
|
7
|
-
import type { DescribeResult, DriverConnection, ExecuteResult, WireValue } from "../../contracts/driver.js";
|
|
7
|
+
import type { DescribeResult, DriverConnection, ExecuteOptions, ExecuteResult, Statement, WireValue } from "../../contracts/driver.js";
|
|
8
8
|
import { type Watch } from "./call.js";
|
|
9
9
|
import { type Canceller, type Counters, type NoticeBuffer } from "./postgresjs.js";
|
|
10
|
+
type Lost = {
|
|
11
|
+
on: boolean;
|
|
12
|
+
/** Rejects the reset or drain that is using this reserved connection. */
|
|
13
|
+
stop: () => void;
|
|
14
|
+
};
|
|
10
15
|
/** State `open` shares with a checkout. */
|
|
11
16
|
export type HeldPool = {
|
|
12
17
|
readonly sql: Sql;
|
|
@@ -23,7 +28,7 @@ export type HeldPool = {
|
|
|
23
28
|
* @param pool - The open pool
|
|
24
29
|
* @returns A connection the caller must release
|
|
25
30
|
*/
|
|
26
|
-
export declare function checkout(pool: HeldPool): Promise<DriverConnection>;
|
|
31
|
+
export declare function checkout(pool: HeldPool, timeoutMs?: number): Promise<DriverConnection>;
|
|
27
32
|
/**
|
|
28
33
|
* Describes a statement.
|
|
29
34
|
*
|
|
@@ -42,18 +47,30 @@ export declare function describe(sql: Sql, text: string, params?: readonly WireV
|
|
|
42
47
|
* @returns Chunks of wire rows
|
|
43
48
|
*/
|
|
44
49
|
export declare function stream(sql: Sql, text: string, params?: readonly WireValue[]): AsyncIterable<readonly (readonly WireValue[])[]>;
|
|
45
|
-
type Lost = {
|
|
46
|
-
on: boolean;
|
|
47
|
-
};
|
|
48
50
|
/**
|
|
49
|
-
*
|
|
51
|
+
* Settles `run` when `ms` elapses, the reserved connection closes, or every
|
|
52
|
+
* slot in the pool has closed.
|
|
50
53
|
*
|
|
51
|
-
*
|
|
52
|
-
* the
|
|
54
|
+
* A positive `ms` rejects with `timeout` and does not use the pool close hook.
|
|
55
|
+
* `link` is the reserved connection's lost flag, or the pool client.
|
|
53
56
|
*
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
57
|
+
* @param ms - Deadline in milliseconds. `0` waits for a close
|
|
58
|
+
* @param run - Driver operation
|
|
59
|
+
* @param link - Connection flag, or the pool client when the wait has no connection
|
|
60
|
+
* @returns The operation's value
|
|
61
|
+
*/
|
|
62
|
+
export declare function deadline<T>(ms: number, run: () => Promise<T>, link?: Lost | Sql): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Checks out one connection, runs one batch, and releases it.
|
|
65
|
+
*
|
|
66
|
+
* The call timeout covers acquiring the connection and clearing it on release.
|
|
67
|
+
*
|
|
68
|
+
* @param pool - The open pool
|
|
69
|
+
* @param statements - Statements in order
|
|
70
|
+
* @param options - Call timeout and signal
|
|
71
|
+
* @returns One result per statement
|
|
56
72
|
*/
|
|
73
|
+
export declare function runBatch(pool: HeldPool, statements: readonly Statement[], options: ExecuteOptions | undefined): Promise<readonly ExecuteResult[]>;
|
|
57
74
|
/**
|
|
58
75
|
* Sets `lost` when the reserved socket closes.
|
|
59
76
|
*
|
|
@@ -64,7 +81,6 @@ type Lost = {
|
|
|
64
81
|
* @param lost - Set when that socket closes
|
|
65
82
|
*/
|
|
66
83
|
export declare function watchReserved(sql: Sql, lost: Lost): void;
|
|
67
|
-
/** Refcount a checkout or a listener borrows from the pool. */
|
|
68
84
|
type Gate = {
|
|
69
85
|
enter(): void;
|
|
70
86
|
leave(): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared reset and lost-connection guard for a reserved connection.
|
|
3
|
+
*
|
|
4
|
+
* node-postgres, Bun.sql, and PGlite load this with the first reserve.
|
|
5
|
+
* postgres.js keeps its own copy: a second module in that adapter bundle
|
|
6
|
+
* crosses the incremental size gate.
|
|
7
|
+
*/
|
|
8
|
+
/** Set when the reserved socket is gone. */
|
|
9
|
+
export type Lost = {
|
|
10
|
+
on: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Clears session state on a reserved connection.
|
|
14
|
+
*
|
|
15
|
+
* A failed reset rolls back and tries once more. The caller supplies `run`.
|
|
16
|
+
*
|
|
17
|
+
* @param depth - Open transaction depth. Above zero, roll back first
|
|
18
|
+
* @param run - Executes one statement on the reserved connection
|
|
19
|
+
*/
|
|
20
|
+
export declare function resetSession(depth: number, run: (text: string) => Promise<unknown>): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Clears a PGlite session the same way {@link resetSession} clears the others.
|
|
23
|
+
*
|
|
24
|
+
* Rollback goes through the session so its depth is cleared on failure too.
|
|
25
|
+
*
|
|
26
|
+
* @param session - The single PGlite connection
|
|
27
|
+
*/
|
|
28
|
+
export declare function resetQueried(session: {
|
|
29
|
+
inTransaction(): boolean;
|
|
30
|
+
rollback(): Promise<void>;
|
|
31
|
+
query(text: string, params: undefined, watch: undefined): Promise<unknown>;
|
|
32
|
+
}): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Refuses the next statement after the reserved connection is gone.
|
|
35
|
+
*
|
|
36
|
+
* The first lost-connection error sets the flag.
|
|
37
|
+
*
|
|
38
|
+
* @param lost - Set when the socket is gone
|
|
39
|
+
* @param run - The statement
|
|
40
|
+
* @returns The statement, or a closed-pool rejection
|
|
41
|
+
*/
|
|
42
|
+
export declare function refuseWhenLost<T>(lost: Lost, run: () => Promise<T>): Promise<T>;
|
|
@@ -23,13 +23,6 @@ export type NoticeBuffer = {
|
|
|
23
23
|
readonly code?: string | undefined;
|
|
24
24
|
}): void;
|
|
25
25
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Quotes one identifier.
|
|
28
|
-
*
|
|
29
|
-
* @param name - Channel or cursor name
|
|
30
|
-
* @returns A double-quoted identifier
|
|
31
|
-
*/
|
|
32
|
-
export declare function quoteIdent(name: string): string;
|
|
33
26
|
/**
|
|
34
27
|
* An empty notice buffer the pool fills as the server sends notices.
|
|
35
28
|
*
|
|
@@ -81,14 +74,3 @@ export declare class WireSession implements BatchSession {
|
|
|
81
74
|
private watched;
|
|
82
75
|
private finishWatched;
|
|
83
76
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Yields cursor chunks from one connection that is already checked out.
|
|
86
|
-
*
|
|
87
|
-
* The cursor is session-local. `ROLLBACK` in the end drops it.
|
|
88
|
-
*
|
|
89
|
-
* @param run - Executes on the checked-out connection
|
|
90
|
-
* @param text - Query to stream
|
|
91
|
-
* @param params - Wire parameters
|
|
92
|
-
* @returns Chunks of wire rows
|
|
93
|
-
*/
|
|
94
|
-
export declare function cursorStream(run: (text: string, params?: readonly WireValue[]) => Promise<ExecuteResult>, text: string, params: readonly WireValue[] | undefined): AsyncIterable<readonly (readonly WireValue[])[]>;
|