@ultimat3/db 31.7.0 → 31.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/CLAUDE.md +33 -32
- package/README.md +23 -0
- package/package.json +2 -2
- package/src/array-parameter.ts +4 -2
- package/src/client.ts +34 -6
- package/src/copy-in.ts +219 -0
- package/src/drift-findings.ts +4 -1
- package/src/drift-index-keys.ts +54 -0
- package/src/drift.ts +14 -2
- package/src/entity-shape.ts +22 -5
- package/src/errors.ts +2 -0
- package/src/generate-snapshot.ts +3 -0
- package/src/generate.ts +9 -1
- package/src/index-ddl.ts +17 -6
- package/src/index-extension.ts +34 -0
- package/src/index-key-ddl.ts +159 -0
- package/src/index-plan.ts +38 -6
- package/src/index.ts +31 -0
- package/src/introspect-index.ts +110 -0
- package/src/introspect.ts +11 -52
- package/src/migration-lock-lint.ts +184 -0
- package/src/pin-statement.ts +154 -0
- package/src/pool-gate.ts +68 -13
- package/src/pool-pins.ts +74 -17
- package/src/replica-client.ts +15 -0
- package/src/rolling.ts +25 -12
- package/src/slow-statement-log.ts +103 -0
- package/src/snapshot-parse.ts +15 -0
- package/src/statement-excerpt.ts +50 -5
- package/src/table-storage.ts +222 -0
- package/src/transaction-settings.ts +9 -0
- package/src/transaction.ts +11 -1
|
@@ -22,3 +22,12 @@ export function setTransactionSettings(next: SettingsProvider | undefined): void
|
|
|
22
22
|
export function transactionSettings(): LocalSettings | undefined {
|
|
23
23
|
return provider?.();
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether a provider is installed at all, whatever it answers now. `copy-in.ts` asks: Postgres
|
|
28
|
+
* refuses `COPY FROM` on a table under row-level security (`0A000`) with or without a tenant in
|
|
29
|
+
* scope, so the question is "is row security armed", never "is there a tenant right now".
|
|
30
|
+
*/
|
|
31
|
+
export function transactionSettingsInstalled(): boolean {
|
|
32
|
+
return provider !== undefined;
|
|
33
|
+
}
|
package/src/transaction.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { assert, finiteCount, nanoid } from '@ultimat3/core';
|
|
7
7
|
import { baseClient, type DbClient, type DbConnection, isReservable } from './client';
|
|
8
|
+
import type { CopyInClient } from './copy-in';
|
|
8
9
|
import { DbError, serializationExhausted } from './errors';
|
|
9
10
|
import { setLocal } from './local-settings';
|
|
10
11
|
import { createTurnQueue, type TurnQueue } from './pglite-turns';
|
|
@@ -145,7 +146,7 @@ function makeTx(
|
|
|
145
146
|
refuseAbandoned(completing);
|
|
146
147
|
return watched(abort, send());
|
|
147
148
|
};
|
|
148
|
-
|
|
149
|
+
const tx: DbTx = {
|
|
149
150
|
id,
|
|
150
151
|
origin,
|
|
151
152
|
query: <T>(fragment: SqlFragment) => guarded(() => connection.query<T>(fragment)),
|
|
@@ -161,6 +162,15 @@ function makeTx(
|
|
|
161
162
|
else if (outcome.value === 'open' || outcome.value === 'ending') commits.push(effect);
|
|
162
163
|
},
|
|
163
164
|
};
|
|
165
|
+
// Only when the connection copies (`postgresClient`'s pin): a COPY on it is this transaction's,
|
|
166
|
+
// guarded like every statement. Absent, `canCopyIn(tx)` answers false and callers insert.
|
|
167
|
+
const pin = connection as DbClient & Partial<CopyInClient>;
|
|
168
|
+
if (typeof pin.copyIn !== 'function') return tx;
|
|
169
|
+
const copyIn = pin.copyIn.bind(pin);
|
|
170
|
+
return Object.assign(tx, {
|
|
171
|
+
copyIn: (target: SqlFragment, rows: Iterable<readonly unknown[]>) =>
|
|
172
|
+
guarded(() => copyIn(target, rows)),
|
|
173
|
+
});
|
|
164
174
|
}
|
|
165
175
|
|
|
166
176
|
const isAborted = (error: unknown): boolean =>
|