okmodel 0.7.0 → 0.9.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 +14 -0
- package/dist/adapters/capabilities.d.ts +32 -0
- package/dist/adapters/failure.d.ts +1 -1
- package/dist/adapters/pg/bun-sql.d.ts +53 -0
- package/dist/adapters/pg/bunsql-extra.d.ts +1 -1
- package/dist/adapters/pg/bunsql.d.ts +1 -1
- 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 +1 -1
- package/dist/contracts/error.d.ts +1 -1
- package/dist/dialects/pg/ext/btree-gin.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gin.js +20 -0
- package/dist/dialects/pg/ext/btree-gist.d.ts +26 -0
- package/dist/dialects/pg/ext/btree-gist.js +20 -0
- package/dist/dialects/pg/ext/call.d.ts +53 -0
- package/dist/dialects/pg/ext/citext.js +1 -1
- package/dist/dialects/pg/ext/feature.d.ts +26 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.d.ts +34 -0
- package/dist/dialects/pg/ext/fuzzystrmatch.js +33 -0
- package/dist/dialects/pg/ext/hstore.d.ts +41 -0
- package/dist/dialects/pg/ext/hstore.js +29 -0
- package/dist/dialects/pg/ext/index.d.ts +56 -0
- package/dist/dialects/pg/ext/index.js +1 -1
- package/dist/dialects/pg/ext/ltree.d.ts +41 -0
- package/dist/dialects/pg/ext/ltree.js +29 -0
- package/dist/dialects/pg/ext/pg-trgm.js +4 -13
- package/dist/dialects/pg/ext/pgcrypto.d.ts +33 -0
- package/dist/dialects/pg/ext/pgcrypto.js +33 -0
- package/dist/dialects/pg/ext/unaccent.d.ts +26 -0
- package/dist/dialects/pg/ext/unaccent.js +21 -0
- package/dist/dialects/pg/ext/using.d.ts +23 -0
- package/dist/dialects/pg/ext/versions.d.ts +36 -0
- package/dist/dialects/pg/external.d.ts +19 -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 +3 -0
- package/dist/dialects/pg/index.js +394 -14
- package/dist/dialects/pg/introspect.d.ts +11 -0
- package/dist/dialects/pg/operators.d.ts +1 -1
- package/dist/dialects/pg/ops/fragment.d.ts +119 -0
- package/dist/dialects/pg/ops/lane.d.ts +49 -0
- 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 +11 -5
- package/dist/runtime/artifact-file.d.ts +22 -0
- package/dist/runtime/client.d.ts +10 -0
- package/dist/runtime/drift-detail.d.ts +2 -1
- package/dist/runtime/drift.d.ts +3 -10
- package/dist/runtime/otel.d.ts +105 -0
- package/dist/runtime/otel.js +97 -0
- package/dist/runtime/pg/bun.js +4 -4
- package/dist/runtime/pg/neon.d.ts +38 -0
- package/dist/runtime/pg/neon.js +64 -0
- package/dist/runtime/pg/pg.js +4 -4
- package/dist/runtime/pg/pglite.js +4 -4
- package/dist/runtime/pg/postgresjs.js +4 -4
- package/dist/runtime/plan.d.ts +1 -1
- package/dist/runtime/server-check.d.ts +36 -6
- package/dist/runtime/sql-fragment.d.ts +43 -0
- package/dist/runtime/tenancy/index.js +10 -10
- package/dist/runtime/topology.d.ts +1 -1
- package/dist/runtime/traits/index.js +16 -17
- package/dist/runtime/types.d.ts +15 -1
- package/dist/runtime/validate/index.js +4 -4
- package/dist/shared/{81ebdx9p.js → 0j6qe91y.js} +4 -4
- package/dist/shared/{qq3899ht.js → 12z7aznj.js} +243 -14
- package/dist/shared/{gzaveazc.js → 1d9q9cv2.js} +29 -2
- package/dist/shared/{w79hsckn.js → 1mxm04fy.js} +5 -5
- package/dist/shared/{7k9grvf6.js → 2szgv6yj.js} +5 -5
- package/dist/shared/{gs74dbj5.js → 2zdxkt7b.js} +933 -111
- package/dist/shared/{m6p12kbr.js → 3456242y.js} +23 -23
- package/dist/shared/3bb7wsqt.js +99 -0
- package/dist/shared/{y6njgyda.js → 3t6kw83m.js} +2 -2
- package/dist/shared/{xhfsfkgk.js → 4vbf83xx.js} +9 -2
- package/dist/shared/{pt94kz7f.js → 5kyb3tqx.js} +1 -1
- package/dist/shared/61bmrmhr.js +35 -0
- package/dist/shared/{x933k9a3.js → 62b603gr.js} +10 -10
- package/dist/shared/{jgqj11w4.js → 6f0z3hzh.js} +4 -0
- package/dist/shared/{tsvww22q.js → 6nae0spm.js} +156 -95
- package/dist/shared/{mtaszv5a.js → 71n0jmhc.js} +102 -4
- package/dist/shared/{5e3tf63j.js → 760ppr76.js} +14 -6
- package/dist/shared/7ba5h6pb.js +17 -0
- package/dist/shared/{sfz1ksn6.js → 8jesqsrk.js} +2 -2
- package/dist/shared/{5v3xf80k.js → 8n688yjg.js} +1 -1
- package/dist/shared/{rs73fca9.js → 8qzkd9f3.js} +6 -6
- package/dist/shared/{ax7qv55k.js → 90sg0w5a.js} +202 -25
- package/dist/shared/{zm0ptry0.js → 99qp9vtg.js} +1 -1
- package/dist/shared/{xnxsed62.js → 9dr2qnx7.js} +14 -14
- package/dist/shared/{1w508jbr.js → 9dtgn1z2.js} +21 -17
- package/dist/shared/{h15jx9bc.js → 9dvh1dr6.js} +1 -1
- package/dist/shared/{q5c6ngn3.js → a62rb2da.js} +1 -1
- package/dist/shared/{te5as7z7.js → aksb89mn.js} +3 -3
- package/dist/shared/{bz84tkzm.js → bphrgwz9.js} +2 -2
- package/dist/shared/bsek72fg.js +225 -0
- package/dist/shared/{7mnme5tn.js → c3mvnq7a.js} +1 -1
- package/dist/shared/{p6qc5gcp.js → ccsmhv9r.js} +25 -7
- package/dist/shared/{pbp1ss85.js → cexb7z6b.js} +2 -2
- package/dist/shared/{ab9gmbwy.js → cf8zdz5p.js} +5 -5
- package/dist/shared/{jvd0mqag.js → ckz05z15.js} +5 -5
- package/dist/shared/{dk8v79p3.js → d5nmj7vv.js} +1 -1
- package/dist/shared/{14vx95q4.js → dd5pmnky.js} +7 -7
- package/dist/shared/{vb6qfyve.js → ds229x4r.js} +2 -2
- package/dist/shared/{1qa0qajz.js → e275q7sd.js} +1 -1
- package/dist/shared/{zp9fmend.js → ebhz8vh6.js} +4 -4
- package/dist/shared/{hyh73qk6.js → ecn8mfdq.js} +5 -5
- package/dist/shared/{je4axnm8.js → fdsz3w80.js} +2 -2
- package/dist/shared/{9s0ypp87.js → fk9vef30.js} +85 -74
- package/dist/shared/{g6evj1j3.js → g89fmz5s.js} +1 -1
- package/dist/shared/{aytqh5y2.js → ghqzdp94.js} +2 -2
- package/dist/shared/h9811jjm.js +17 -0
- package/dist/shared/{dkxgzaqd.js → hqpxf4a4.js} +1 -1
- package/dist/shared/{8skf0cam.js → jpybhf98.js} +1 -1
- package/dist/shared/{67txcrcw.js → kgwp4jdd.js} +4 -4
- package/dist/shared/kzgrnckd.js +29 -0
- package/dist/shared/mazpbcdj.js +233 -0
- package/dist/shared/{kb2sdhfb.js → mfvx6kjx.js} +17 -1
- package/dist/shared/{svncdeh5.js → mgaq2sd3.js} +11 -8
- package/dist/shared/{5mtf6cj3.js → mvmm3xpb.js} +5 -2
- package/dist/shared/{b5pftnn2.js → myk8fswx.js} +66 -21
- package/dist/shared/{2shdbn8q.js → n306gqkd.js} +9 -9
- package/dist/shared/{n816peh1.js → n454kcnw.js} +1 -1
- package/dist/shared/n5whk3mt.js +665 -0
- package/dist/shared/n7kg8mmx.js +61 -0
- package/dist/shared/{vqrjpcqn.js → nmnsgj7x.js} +1 -1
- package/dist/shared/{tbrvgw6z.js → npdftanb.js} +19 -26
- package/dist/shared/{ek2wt2dz.js → pg4ezgyf.js} +11 -30
- package/dist/shared/{5fe3kbsh.js → pgsak1yw.js} +1 -1
- package/dist/shared/{bm22fvzr.js → qfw14tna.js} +2 -2
- package/dist/shared/{wa07eas9.js → qvwwp1mp.js} +62 -41
- package/dist/shared/rbxt795q.js +1766 -0
- package/dist/shared/{xjk7hnn5.js → s7he5e5d.js} +2 -2
- package/dist/shared/{w72kgg4q.js → ss2kv2rs.js} +6 -6
- package/dist/shared/stfa9xcw.js +450 -0
- package/dist/shared/{3v7t1yrv.js → th3be82n.js} +2 -2
- package/dist/shared/{79dt02vc.js → tr64w5p0.js} +1 -1
- package/dist/shared/{cn957f8d.js → tw1nvvfj.js} +3 -3
- package/dist/shared/{ed0b8k4s.js → typ3vy7t.js} +1 -1
- package/dist/shared/{9628a9xt.js → vk7rag46.js} +1 -1
- package/dist/shared/{ze4hxsmy.js → w9ejzaqf.js} +1 -1
- package/dist/shared/{vczs8gd4.js → wvtjg5m3.js} +2 -2
- package/dist/shared/{9y3mmmh1.js → xfhe73sb.js} +1 -1
- package/dist/shared/xqacq37x.js +61 -0
- package/dist/shared/{1est4ezg.js → xtsydxjg.js} +3 -3
- package/dist/shared/xv8qj97g.js +96 -0
- package/dist/shared/{bg3rym3g.js → xwhdcrm4.js} +2 -2
- package/dist/shared/{kr0jzbw2.js → yvabyg9k.js} +7 -7
- package/dist/shared/yybhre6n.js +136 -0
- package/dist/shared/zdqf8k5d.js +8 -0
- package/dist/shared/{jznfax0y.js → zq1he88x.js} +4 -4
- package/dist/tooling/cli.js +108 -23
- package/dist/tooling/driver-run.js +4654 -0
- package/dist/tooling/driver-test.d.ts +36 -0
- package/dist/tooling/github/comment.d.ts +50 -0
- package/dist/tooling/github/post-comment.d.ts +17 -0
- package/dist/tooling/migrate/commands.d.ts +3 -2
- package/dist/tooling/migrate/config.d.ts +13 -0
- package/dist/tooling/migrate/export.d.ts +165 -0
- package/dist/tooling/migrate/ext-surface.d.ts +80 -0
- package/dist/tooling/migrate/ext.d.ts +31 -4
- package/dist/tooling/migrate/import-drizzle.d.ts +40 -0
- package/dist/tooling/migrate/index.d.ts +3 -0
- package/dist/tooling/migrate/index.js +55 -10
- package/dist/tooling/migrate/lint-rules.d.ts +18 -1
- package/dist/tooling/migrate/lint.d.ts +14 -1
- package/dist/tooling/migrate/place.d.ts +18 -0
- package/dist/tooling/migrate/plan-json.d.ts +65 -0
- package/dist/tooling/migrate/project.d.ts +13 -1
- package/dist/tooling/migrate/pull-emit.d.ts +98 -0
- package/dist/tooling/migrate/pull-routines.d.ts +126 -0
- package/dist/tooling/migrate/pull-verify.d.ts +26 -0
- package/dist/tooling/migrate/pull.d.ts +62 -0
- package/dist/tooling/migrate/reprint.d.ts +32 -0
- package/dist/tooling/migrate/sandbox.d.ts +8 -2
- package/dist/tooling/migrate/schema-api.d.ts +43 -0
- package/dist/tooling/migrate/sql-lex.d.ts +18 -0
- package/dist/tooling/shared/04svnxxj.js +344 -0
- package/dist/tooling/shared/0j0jtse1.js +13 -0
- package/dist/tooling/shared/0r05zhyq.js +618 -0
- package/dist/tooling/shared/1800eymw.js +49 -0
- package/dist/tooling/shared/35zemrmf.js +12 -0
- package/dist/tooling/shared/3rmaz3pq.js +140 -0
- package/dist/tooling/shared/3yn79q5m.js +12 -0
- package/dist/tooling/shared/54tqkxja.js +51 -0
- package/dist/tooling/shared/57btdkgm.js +209 -0
- package/dist/tooling/shared/5bmksndh.js +118 -0
- package/dist/tooling/shared/5p8km5jb.js +38 -0
- package/dist/tooling/shared/5x3pf400.js +185 -0
- package/dist/tooling/shared/5zrzffnk.js +6 -0
- package/dist/tooling/shared/62fxpc1p.js +332 -0
- package/dist/tooling/shared/68tf18v4.js +20 -0
- package/dist/tooling/shared/6vk28rjp.js +98 -0
- package/dist/tooling/shared/76pv6qff.js +9 -0
- package/dist/tooling/shared/7aews1zg.js +311 -0
- package/dist/tooling/shared/7b3xp9gc.js +195 -0
- package/dist/tooling/shared/7kms6fvj.js +20 -0
- package/dist/tooling/shared/7pxncnzs.js +40 -0
- package/dist/tooling/shared/829fjxyw.js +198 -0
- package/dist/tooling/shared/8m5znpdt.js +66 -0
- package/dist/tooling/shared/8yr7ges1.js +211 -0
- package/dist/tooling/shared/96ps4g1z.js +32 -0
- package/dist/tooling/shared/9qr9rkbh.js +143 -0
- package/dist/tooling/shared/9sfbtwsk.js +49 -0
- package/dist/tooling/shared/9wsnsvbf.js +10 -0
- package/dist/tooling/shared/a2xe04bm.js +18 -0
- package/dist/tooling/shared/a4pzghha.js +20 -0
- package/dist/tooling/shared/am04v8na.js +233 -0
- package/dist/tooling/shared/asgr07mp.js +194 -0
- package/dist/tooling/shared/c0xevn1h.js +312 -0
- package/dist/tooling/shared/dhatassp.js +134 -0
- package/dist/tooling/shared/ezqn88nj.js +1696 -0
- package/dist/tooling/shared/f77nnfqy.js +231 -0
- package/dist/tooling/shared/fh07z1dt.js +15 -0
- package/dist/tooling/shared/gqwevek4.js +81 -0
- package/dist/tooling/shared/hfq3n3bd.js +4116 -0
- package/dist/tooling/shared/htnaj77v.js +17 -0
- package/dist/tooling/shared/j664qjrt.js +64 -0
- package/dist/tooling/shared/jpgmjsx3.js +38 -0
- package/dist/tooling/shared/jr2nmr81.js +497 -0
- package/dist/tooling/shared/jsjjz875.js +139 -0
- package/dist/tooling/shared/kbqnrs1x.js +1425 -0
- package/dist/tooling/shared/kz715295.js +94 -0
- package/dist/tooling/shared/m3xt8b1h.js +22 -0
- package/dist/tooling/shared/m4hhb8aa.js +9 -0
- package/dist/tooling/shared/mw5npye0.js +16 -0
- package/dist/tooling/shared/n4jqhpqz.js +27 -0
- package/dist/tooling/shared/nxq95eb6.js +42 -0
- package/dist/tooling/shared/qartgazh.js +70 -0
- package/dist/tooling/shared/rcywj2w8.js +190 -0
- package/dist/tooling/shared/s6qha57m.js +16 -0
- package/dist/tooling/shared/shjs0379.js +150 -0
- package/dist/tooling/shared/sjwkt1pg.js +16 -0
- package/dist/tooling/shared/stebqyyd.js +401 -0
- package/dist/tooling/shared/t4xveemq.js +250 -0
- package/dist/tooling/shared/t6zjeake.js +261 -0
- package/dist/tooling/shared/tcwpjvxe.js +9 -0
- package/dist/tooling/shared/tpssp7ac.js +160 -0
- package/dist/tooling/shared/v6j1ep6w.js +42 -0
- package/dist/tooling/shared/vwr2y833.js +270 -0
- package/dist/tooling/shared/w17sj05d.js +7 -0
- package/dist/tooling/shared/w5d89rb4.js +131 -0
- package/dist/tooling/shared/wbwq1jsa.js +157 -0
- package/dist/tooling/shared/wezxf3h8.js +17 -0
- package/dist/tooling/shared/yb4kd19s.js +12 -0
- package/dist/tooling/shared/ybdew6j7.js +294 -0
- package/dist/tooling/shared/yfedr1zb.js +6 -0
- package/dist/tooling/shared/yhp829bx.js +177 -0
- package/dist/tooling/shared/ytk1tjs0.js +604 -0
- package/dist/tooling/shared/zs9aymcp.js +210 -0
- package/dist/tooling/shared/zx3v9phv.js +8 -0
- package/dist/tooling/testing/index.js +3 -3
- package/package.json +50 -9
- package/dist/shared/ktz42yez.js +0 -113
- package/dist/shared/ttsqgp4p.js +0 -71
- package/dist/shared/y34a8714.js +0 -150
- 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
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DriverError2,
|
|
3
|
+
timedOut2,
|
|
4
|
+
isConnectionLost
|
|
5
|
+
} from "./hfq3n3bd.js";
|
|
6
|
+
import {
|
|
7
|
+
PgSession2
|
|
8
|
+
} from "./62fxpc1p.js";
|
|
9
|
+
import {
|
|
10
|
+
driverErrors,
|
|
11
|
+
rejectClosed,
|
|
12
|
+
mapFailure,
|
|
13
|
+
runCall,
|
|
14
|
+
rowsFrom,
|
|
15
|
+
resultFrom
|
|
16
|
+
} from "./5x3pf400.js";
|
|
17
|
+
|
|
18
|
+
// src/adapters/pg/postgres-extra.ts
|
|
19
|
+
var RESET_ALL = "RESET ALL";
|
|
20
|
+
var UNLOCK = "SELECT pg_advisory_unlock_all()";
|
|
21
|
+
async function checkout(pool, timeoutMs) {
|
|
22
|
+
if (pool.isClosed())
|
|
23
|
+
return rejectClosed();
|
|
24
|
+
const reserved = await reserveConnection(pool.sql, pool.acquireMs, pool.counters, timeoutMs);
|
|
25
|
+
pool.counters.reserved += 1;
|
|
26
|
+
const local = new Set;
|
|
27
|
+
const session = new PgSession2(reserved, pool.counters, "reserved", local, pool.isClosed, pool.poolInflight, pool.notices, pool.named);
|
|
28
|
+
let released = false;
|
|
29
|
+
const lost = { on: false, stop: () => {
|
|
30
|
+
return;
|
|
31
|
+
} };
|
|
32
|
+
arm(reserved, lost);
|
|
33
|
+
let limit = timeoutMs !== undefined && timeoutMs > 0 ? timeoutMs : 0;
|
|
34
|
+
const remember = (timeout) => {
|
|
35
|
+
if (timeout !== undefined && timeout > 0)
|
|
36
|
+
limit = timeout;
|
|
37
|
+
};
|
|
38
|
+
const guard = (run) => lost.on ? rejectClosed() : run().catch((error) => {
|
|
39
|
+
if (isConnectionLost(error))
|
|
40
|
+
lost.on = true;
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
execute: (text, params, options) => {
|
|
45
|
+
remember(options?.timeout);
|
|
46
|
+
return guard(() => runCall(pool.isClosed(), options, (watch) => session.query(text, params, watch)));
|
|
47
|
+
},
|
|
48
|
+
batch: (statements, options) => {
|
|
49
|
+
remember(options?.timeout);
|
|
50
|
+
return guard(() => runCall(pool.isClosed(), options, async (watch) => {
|
|
51
|
+
const { runAtomicBatch } = await import("./gqwevek4.js");
|
|
52
|
+
return runAtomicBatch(session, statements, watch);
|
|
53
|
+
}));
|
|
54
|
+
},
|
|
55
|
+
cancel() {
|
|
56
|
+
session.cancel();
|
|
57
|
+
},
|
|
58
|
+
async release() {
|
|
59
|
+
if (released)
|
|
60
|
+
return;
|
|
61
|
+
released = true;
|
|
62
|
+
const ms = limit;
|
|
63
|
+
try {
|
|
64
|
+
if (!lost.on)
|
|
65
|
+
await deadline(ms, () => resetConnection(reserved, session.depth()), lost);
|
|
66
|
+
} catch {
|
|
67
|
+
lost.on = true;
|
|
68
|
+
} finally {
|
|
69
|
+
pool.counters.reserved = Math.max(0, pool.counters.reserved - 1);
|
|
70
|
+
if (lost.on)
|
|
71
|
+
await deadline(ms, () => pool.sql.unsafe("select 1"), pool.sql).catch(() => {
|
|
72
|
+
return;
|
|
73
|
+
});
|
|
74
|
+
else
|
|
75
|
+
reserved.release();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async function describe(sql, text, params) {
|
|
81
|
+
const pending = sql.unsafe(text, asParams(params), { prepare: true });
|
|
82
|
+
const described = await pending.describe();
|
|
83
|
+
return {
|
|
84
|
+
columns: described.columns.map((column) => column.name),
|
|
85
|
+
parameterCount: described.types.length
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
async function* stream(sql, text, params) {
|
|
89
|
+
const pending = sql.unsafe(text, asParams(params));
|
|
90
|
+
for await (const chunk of pending.cursor(64)) {
|
|
91
|
+
yield rowsFrom(chunk);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function poolWaits(sql) {
|
|
95
|
+
const options = sql.options;
|
|
96
|
+
if (options === undefined || options.q !== undefined)
|
|
97
|
+
return options;
|
|
98
|
+
const q = new Set;
|
|
99
|
+
const n = new Set;
|
|
100
|
+
options.q = q;
|
|
101
|
+
options.n = n;
|
|
102
|
+
options.onclose = (id) => {
|
|
103
|
+
n.add(id);
|
|
104
|
+
if (n.size < options.max) {
|
|
105
|
+
queueMicrotask(() => {
|
|
106
|
+
for (const wait of q)
|
|
107
|
+
wait.a();
|
|
108
|
+
});
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
n.clear();
|
|
112
|
+
for (const wait of q)
|
|
113
|
+
wait.s();
|
|
114
|
+
q.clear();
|
|
115
|
+
};
|
|
116
|
+
return options;
|
|
117
|
+
}
|
|
118
|
+
function deadline(ms, run, link) {
|
|
119
|
+
let timer;
|
|
120
|
+
let off = () => {
|
|
121
|
+
return;
|
|
122
|
+
};
|
|
123
|
+
const slot = link !== undefined && "stop" in link ? link : undefined;
|
|
124
|
+
const pool = slot === undefined && link !== undefined ? poolWaits(link) : undefined;
|
|
125
|
+
let ended = false;
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
const fail = (error) => {
|
|
128
|
+
if (ended)
|
|
129
|
+
return;
|
|
130
|
+
ended = true;
|
|
131
|
+
reject(error);
|
|
132
|
+
};
|
|
133
|
+
const stop = () => {
|
|
134
|
+
fail(new DriverError2("Connection closed", { sqlstate: "08006" }));
|
|
135
|
+
};
|
|
136
|
+
if (slot !== undefined)
|
|
137
|
+
slot.stop = stop;
|
|
138
|
+
const go = () => {
|
|
139
|
+
const pending = run();
|
|
140
|
+
if (ms > 0 && timer === undefined) {
|
|
141
|
+
timer = setTimeout(() => {
|
|
142
|
+
pending.cancel?.();
|
|
143
|
+
fail(timedOut2());
|
|
144
|
+
}, ms);
|
|
145
|
+
}
|
|
146
|
+
pending.then((value) => {
|
|
147
|
+
if (ended) {
|
|
148
|
+
value.release?.();
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
ended = true;
|
|
152
|
+
pool?.n?.clear();
|
|
153
|
+
resolve(value);
|
|
154
|
+
}, fail);
|
|
155
|
+
};
|
|
156
|
+
if (ms === 0 && pool?.q !== undefined) {
|
|
157
|
+
let used = false;
|
|
158
|
+
const wait = {
|
|
159
|
+
s: stop,
|
|
160
|
+
a() {
|
|
161
|
+
if (used || ended)
|
|
162
|
+
return;
|
|
163
|
+
used = true;
|
|
164
|
+
go();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
pool.q.add(wait);
|
|
168
|
+
off = () => pool.q?.delete(wait);
|
|
169
|
+
}
|
|
170
|
+
go();
|
|
171
|
+
}).finally(() => {
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
if (slot !== undefined)
|
|
174
|
+
slot.stop = () => {
|
|
175
|
+
return;
|
|
176
|
+
};
|
|
177
|
+
off();
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
async function runBatch(pool, statements, options) {
|
|
181
|
+
const connection = await checkout(pool, options?.timeout);
|
|
182
|
+
try {
|
|
183
|
+
return await connection.batch(statements, options);
|
|
184
|
+
} finally {
|
|
185
|
+
await connection.release();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function reserveConnection(sql, acquireMs, counters, callMs) {
|
|
189
|
+
counters.waiting += 1;
|
|
190
|
+
let settled = false;
|
|
191
|
+
const finish = () => {
|
|
192
|
+
counters.waiting = Math.max(0, counters.waiting - 1);
|
|
193
|
+
};
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
let timer;
|
|
196
|
+
if (acquireMs !== undefined) {
|
|
197
|
+
timer = setTimeout(() => {
|
|
198
|
+
if (settled)
|
|
199
|
+
return;
|
|
200
|
+
settled = true;
|
|
201
|
+
finish();
|
|
202
|
+
driverErrors().then((errors) => {
|
|
203
|
+
reject(errors.acquireTimeout());
|
|
204
|
+
});
|
|
205
|
+
}, acquireMs);
|
|
206
|
+
}
|
|
207
|
+
const ms = callMs !== undefined && callMs > 0 ? callMs : 0;
|
|
208
|
+
deadline(ms, () => sql.reserve(), sql).then((connection) => {
|
|
209
|
+
if (settled) {
|
|
210
|
+
resetConnection(connection, 0).catch(() => {
|
|
211
|
+
return;
|
|
212
|
+
}).finally(() => {
|
|
213
|
+
connection.release();
|
|
214
|
+
});
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
settled = true;
|
|
218
|
+
if (timer !== undefined)
|
|
219
|
+
clearTimeout(timer);
|
|
220
|
+
finish();
|
|
221
|
+
resolve(connection);
|
|
222
|
+
}, (error) => {
|
|
223
|
+
if (settled)
|
|
224
|
+
return;
|
|
225
|
+
settled = true;
|
|
226
|
+
if (timer !== undefined)
|
|
227
|
+
clearTimeout(timer);
|
|
228
|
+
finish();
|
|
229
|
+
mapFailure(error).then(reject);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
async function resetConnection(sql, depth) {
|
|
234
|
+
if (depth > 0)
|
|
235
|
+
await sql.unsafe("ROLLBACK").catch(() => {
|
|
236
|
+
return;
|
|
237
|
+
});
|
|
238
|
+
try {
|
|
239
|
+
await sql.unsafe(RESET_ALL);
|
|
240
|
+
await sql.unsafe(UNLOCK);
|
|
241
|
+
} catch {
|
|
242
|
+
await sql.unsafe("ROLLBACK").catch(() => {
|
|
243
|
+
return;
|
|
244
|
+
});
|
|
245
|
+
await sql.unsafe(RESET_ALL);
|
|
246
|
+
await sql.unsafe(UNLOCK);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
function asParams(params) {
|
|
250
|
+
if (params === undefined)
|
|
251
|
+
return [];
|
|
252
|
+
return params;
|
|
253
|
+
}
|
|
254
|
+
function arm(sql, lost) {
|
|
255
|
+
const unsafe = sql.unsafe.bind(sql);
|
|
256
|
+
sql.unsafe = (text, params, options) => unsafe(text, params, {
|
|
257
|
+
...options,
|
|
258
|
+
onexecute(connection) {
|
|
259
|
+
connection.onclose = () => {
|
|
260
|
+
lost.on = true;
|
|
261
|
+
lost.stop();
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
async function holdCheckout(gate, checkout) {
|
|
267
|
+
try {
|
|
268
|
+
const connection = await checkout();
|
|
269
|
+
let released = false;
|
|
270
|
+
const release = connection.release.bind(connection);
|
|
271
|
+
connection.release = () => {
|
|
272
|
+
if (released)
|
|
273
|
+
return Promise.resolve();
|
|
274
|
+
released = true;
|
|
275
|
+
return release().finally(() => {
|
|
276
|
+
gate.leave();
|
|
277
|
+
});
|
|
278
|
+
};
|
|
279
|
+
return connection;
|
|
280
|
+
} catch (error) {
|
|
281
|
+
gate.leave();
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
async function holdListener(gate, start) {
|
|
286
|
+
try {
|
|
287
|
+
const stop = await start();
|
|
288
|
+
let stopped = false;
|
|
289
|
+
return async () => {
|
|
290
|
+
if (stopped)
|
|
291
|
+
return;
|
|
292
|
+
stopped = true;
|
|
293
|
+
try {
|
|
294
|
+
await stop();
|
|
295
|
+
} finally {
|
|
296
|
+
gate.leave();
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
gate.leave();
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function watchQuery(pending, watch, onAbort, ctx) {
|
|
305
|
+
return pending.then((value) => {
|
|
306
|
+
finishWatch(pending, watch, onAbort, ctx);
|
|
307
|
+
const why = watch.reason();
|
|
308
|
+
if (why === "timeout" || why === "cancelled")
|
|
309
|
+
return classify(why, watch);
|
|
310
|
+
ctx.note(ctx.text);
|
|
311
|
+
return resultFrom(value, ctx.notices.since(ctx.start));
|
|
312
|
+
}, (error) => {
|
|
313
|
+
finishWatch(pending, watch, onAbort, ctx);
|
|
314
|
+
return classify(error, watch);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function finishWatch(pending, watch, onAbort, ctx) {
|
|
318
|
+
ctx.leave();
|
|
319
|
+
ctx.untrack(pending);
|
|
320
|
+
watch.signal.removeEventListener("abort", onAbort);
|
|
321
|
+
}
|
|
322
|
+
async function classify(error, watch) {
|
|
323
|
+
const errors = await driverErrors();
|
|
324
|
+
if (error instanceof errors.DriverError)
|
|
325
|
+
return Promise.reject(error);
|
|
326
|
+
const why = typeof error === "string" ? error : watch.reason();
|
|
327
|
+
if (why === "timeout") {
|
|
328
|
+
return Promise.reject(errors.timedOut(typeof error === "string" ? undefined : error));
|
|
329
|
+
}
|
|
330
|
+
const code = errors.errorField(error, "code");
|
|
331
|
+
if (why === "cancelled" || code === "57014") {
|
|
332
|
+
return Promise.reject(errors.cancelled(typeof error === "string" ? undefined : error));
|
|
333
|
+
}
|
|
334
|
+
return Promise.reject(errors.mapDriverError(error));
|
|
335
|
+
}
|
|
336
|
+
export {
|
|
337
|
+
checkout,
|
|
338
|
+
describe,
|
|
339
|
+
holdCheckout,
|
|
340
|
+
holdListener,
|
|
341
|
+
runBatch,
|
|
342
|
+
stream,
|
|
343
|
+
watchQuery
|
|
344
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
fail2
|
|
3
|
+
} from "./hfq3n3bd.js";
|
|
4
|
+
|
|
5
|
+
// src/runtime/result-name.ts
|
|
6
|
+
var PROTOTYPE_KEYS = ",__proto__,constructor,toString,hasOwnProperty,valueOf,isPrototypeOf,propertyIsEnumerable,toLocaleString,__defineGetter__,__defineSetter__,__lookupGetter__,__lookupSetter__,then,";
|
|
7
|
+
function refusePrototypeKey(name, where) {
|
|
8
|
+
if (!PROTOTYPE_KEYS.includes(`,${name},`))
|
|
9
|
+
return;
|
|
10
|
+
fail2("OKM1120", `${where} ${name} is a prototype key. Use another name for the result.`);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { refusePrototypeKey };
|