@zmdb/postgres 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # @zmdb/postgres
2
+
3
+ The PostgreSQL vertical owns the immutable `postgres` dialect, its migration hooks and catalog introspector, and the `postgresDriver` adapter. The shared query compiler comes from `@zmdb/sql`;
4
+ repository and driver contracts come from `@zmdb/orm`. `postgresVertical` pairs this dialect with its driver factory.
5
+
6
+ ## Install
7
+
8
+ ```bash
9
+ yarn add @zmdb/postgres@1.0.0-beta.1 @zmdb/sql@1.0.0-beta.1 @zmdb/migrations@1.0.0-beta.1 pg@^8.23.0
10
+ ```
11
+
12
+ For the TypeScript snippets, install the declaration inputs used by the packed consumer:
13
+
14
+ ```bash
15
+ yarn add --dev typescript@7.0.2 @types/node@26.4.1 @types/pg@8.23.1
16
+ ```
17
+
18
+ Use Node.js 26+ and ESM. Keep the required `@zmdb/sql` and `@zmdb/orm` peers aligned with this package's version; npm resolves those peers. An application already using `zmdb` adds its selected
19
+ database package and client rather than replacing the product facade.
20
+
21
+ `pg` is an optional peer in package metadata because callers supply the structural client. Install it explicitly for this node-postgres recipe; importing the vertical itself does not import the SDK or
22
+ create a pool.
23
+
24
+ ## Configure
25
+
26
+ The snippets below are successive steps in one module.
27
+
28
+ ```ts
29
+ import { Pool } from 'pg';
30
+ import { postgres, postgresDriver } from '@zmdb/postgres';
31
+
32
+ const client = new Pool({ connectionString: process.env.DATABASE_URL });
33
+ const driver = postgresDriver(client);
34
+ ```
35
+
36
+ The application owns the client and closes it with `await client.end()` in a `finally` block after its work. Hosted services that accept this client's protocol are connection recipes, not additional
37
+ official database packages or automatically qualified server variants.
38
+
39
+ ## Compile
40
+
41
+ ```ts
42
+ import { createQueryCompiler } from '@zmdb/sql';
43
+
44
+ const compiler = createQueryCompiler(postgres);
45
+ const query = compiler.selectFrom('users').where('id', '=', 7).compile();
46
+ ```
47
+
48
+ Compilation is pure: the result carries SQL text and a separate parameter array. It does not create the `users` table or open a connection.
49
+
50
+ ## Migrate
51
+
52
+ Use `postgres.migrations.emitUp(operation)` to obtain this database's DDL and `postgres.migrations.connection(driver)` to create its migration connection. Pass reviewed migration records to `up` and
53
+ `down` from `@zmdb/migrations`; transactional behavior follows the capability table below. The [complete installed workflow](../../fixtures/consumer-database-publication/runtime.mjs) creates a fresh
54
+ table, applies and rolls back its migration, and closes the supplied client.
55
+
56
+ ## Introspect
57
+
58
+ ```ts
59
+ const snapshot = await postgres.introspector.snapshot(driver);
60
+ ```
61
+
62
+ The snapshot comes from the selected database's real catalog through the same driver. `postgresIntrospector` is also exported directly. Introspection and generated DDL use this vertical's semantics.
63
+
64
+ ## Execute
65
+
66
+ ```ts
67
+ const rows = await driver.execute(query);
68
+ ```
69
+
70
+ Run this after migrating or otherwise creating the table. Use `driver.transaction(async transaction => ...)` for a pinned transactional driver; the application decides whether to retry. Query values
71
+ travel as parameters, not SQL string interpolation.
72
+
73
+ ## Capabilities
74
+
75
+ These entries describe `postgres.capabilities`; a true entry can still require the client support described below.
76
+
77
+ | Capability | Advertised support |
78
+ | ------------------------------------- | ------------------ |
79
+ | INSERT/upsert/UPDATE/DELETE returning | yes |
80
+ | Transactional DDL | yes |
81
+ | Schemas | yes |
82
+ | Sequences | yes |
83
+ | Generated columns | yes |
84
+ | Partial indexes | yes |
85
+ | Foreign keys | yes |
86
+ | Row-level security | yes |
87
+ | Streaming | yes |
88
+ | Server-side cancellation | yes |
89
+
90
+ ## Refusals and ownership
91
+
92
+ Cursor streaming requires a queryable that can check out a client. Server-side cancellation additionally requires an independent queryable through `PgOptions.cancelVia`; the basic pool example does
93
+ not enable it. Retrying a transaction is explicit and reruns its callback, so keep non-idempotent external effects outside that callback.
94
+
95
+ PostgreSQL owns the parent dialect. Its public `postgresFamilyDriver`, `postgresFamilyIntrospector` and `postgresFamilyMigrations` let `@zmdb/cockroach` supply its own dialect and overrides. The
96
+ dependency points from CockroachDB to PostgreSQL; the parent does not install or inspect its child.
97
+
98
+ `postgresOutboxMigration(version)` provides the PostgreSQL outbox table, defaults and partial pending index as an ordinary migration.
99
+
100
+ ## Testing evidence
101
+
102
+ The [database publication qualification](../../fixtures/consumer-database-publication) builds real npm archives and installs this selected package in an independent consumer. Its public workflow
103
+ covers strict declarations, package/client ownership, parameterized CRUD, transaction rollback, migration application/rollback and catalog introspection. The
104
+ [PostgreSQL consumer](../../fixtures/database-postgres) adds the database-specific capability and refusal checks.
105
+
106
+ Issue [#676](https://github.com/ambasta/zmdb/issues/676) records the completed installed workflows. Those observations are scoped to their recorded clients and servers; they do not certify every
107
+ compatible hosted service. Qualification reports identify their source, archive and server inputs. See the [PostgreSQL guide](../../docs-site/content/dialect-postgres.md) for the detailed contract.
108
+
109
+ ## License
110
+
111
+ GNU General Public License v3.0 or later (GPL-3.0-or-later) — see [LICENSE](./LICENSE).
@@ -0,0 +1,3 @@
1
+ import { type DialectTypeMap } from '@zmdb/sql';
2
+ export declare const POSTGRES_TYPES: DialectTypeMap;
3
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,eAAO,MAAM,cAAc,EAAE,cAW3B,CAAC"}
@@ -0,0 +1,14 @@
1
+ import {} from '@zmdb/sql';
2
+ export const POSTGRES_TYPES = Object.freeze({
3
+ serial: 'SERIAL',
4
+ integer: 'INTEGER',
5
+ bigint: 'BIGINT',
6
+ numeric: 'NUMERIC',
7
+ text: 'TEXT',
8
+ varchar: 'VARCHAR',
9
+ boolean: 'BOOLEAN',
10
+ timestamp: 'TIMESTAMPTZ',
11
+ json: 'JSONB',
12
+ jsonEnum: 'TEXT',
13
+ });
14
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,MAAM,WAAW,CAAC;AAEhD,MAAM,CAAC,MAAM,cAAc,GAAmB,MAAM,CAAC,MAAM,CAAC;IAC1D,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,MAAM;IACZ,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,aAAa;IACxB,IAAI,EAAE,OAAO;IACb,QAAQ,EAAE,MAAM;CACjB,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { type TransactionalDriver } from '@zmdb/orm';
2
+ import { type SqlDialect } from '@zmdb/sql';
3
+ export interface PgQueryable {
4
+ query(text: string, params?: readonly unknown[]): Promise<{
5
+ rows: Record<string, unknown>[];
6
+ }>;
7
+ query(config: {
8
+ readonly name?: string;
9
+ readonly queryMode?: 'extended';
10
+ readonly text: string;
11
+ readonly values?: readonly unknown[];
12
+ }): Promise<{
13
+ rows: Record<string, unknown>[];
14
+ }>;
15
+ connect?(): Promise<PgConnection>;
16
+ }
17
+ export interface PgConnection extends PgQueryable {
18
+ release?(): void;
19
+ }
20
+ export interface PgOptions {
21
+ readonly prepared?: boolean;
22
+ readonly maxCacheSize?: number;
23
+ /** A queryable guaranteed to use a connection other than the running backend. */
24
+ readonly cancelVia?: PgQueryable;
25
+ }
26
+ export declare function postgresFamilyDriver<Name extends string>(dialect: SqlDialect<Name>, client: PgQueryable, options?: PgOptions): TransactionalDriver<Name>;
27
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAsB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAEhE,MAAM,WAAW,WAAW;IAC1B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;IAC/F,KAAK,CAAC,MAAM,EAAE;QACZ,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,UAAU,CAAC;QAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;KACtC,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAA;KAAE,CAAC,CAAC;IACjD,OAAO,CAAC,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CACnC;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,OAAO,CAAC,IAAI,IAAI,CAAC;CAClB;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,SAAS,CAAC,EAAE,WAAW,CAAC;CAClC;AAiBD,wBAAgB,oBAAoB,CAAC,IAAI,SAAS,MAAM,EACtD,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,EACzB,MAAM,EAAE,WAAW,EACnB,OAAO,CAAC,EAAE,SAAS,GAClB,mBAAmB,CAAC,IAAI,CAAC,CAE3B"}
package/dist/driver.js ADDED
@@ -0,0 +1,266 @@
1
+ import {} from '@zmdb/orm';
2
+ import {} from '@zmdb/sql';
3
+ export function postgresFamilyDriver(dialect, client, options) {
4
+ return createPostgresDriver(dialect, client, options, false, new WeakMap());
5
+ }
6
+ function createPostgresDriver(dialect, client, options, pinned, preparedStates) {
7
+ const prepared = options?.prepared ?? false;
8
+ const maxCacheSize = options?.maxCacheSize ?? 1000;
9
+ if (!Number.isSafeInteger(maxCacheSize) || maxCacheSize < 0) {
10
+ throw new RangeError('maxCacheSize must be a non-negative safe integer');
11
+ }
12
+ let cursorSequence = 0;
13
+ const stateFor = (target) => {
14
+ const current = preparedStates.get(target);
15
+ if (current !== undefined)
16
+ return current;
17
+ const created = { names: new Map(), sequence: 0 };
18
+ preparedStates.set(target, created);
19
+ return created;
20
+ };
21
+ const preparedName = async (target, text) => {
22
+ const preparedState = stateFor(target);
23
+ const cached = maxCacheSize > 0 ? preparedState.names.get(text) : undefined;
24
+ if (cached !== undefined) {
25
+ preparedState.names.delete(text);
26
+ preparedState.names.set(text, cached);
27
+ return cached;
28
+ }
29
+ const name = `zmdb_${(preparedState.sequence++).toString(36)}`;
30
+ if (maxCacheSize > 0) {
31
+ if (preparedState.names.size >= maxCacheSize) {
32
+ const oldestSql = preparedState.names.keys().next().value;
33
+ if (oldestSql !== undefined) {
34
+ const oldestName = preparedState.names.get(oldestSql);
35
+ preparedState.names.delete(oldestSql);
36
+ if (oldestName !== undefined)
37
+ await target.query(`DEALLOCATE ${oldestName}`);
38
+ }
39
+ }
40
+ preparedState.names.set(text, name);
41
+ }
42
+ return name;
43
+ };
44
+ const executeOn = async (target, query) => {
45
+ const result = !prepared
46
+ ? await target.query(query.text, query.parameters)
47
+ : maxCacheSize === 0
48
+ ? await target.query({
49
+ queryMode: 'extended',
50
+ text: query.text,
51
+ values: query.parameters,
52
+ })
53
+ : await target.query({
54
+ name: await preparedName(target, query.text),
55
+ text: query.text,
56
+ values: query.parameters,
57
+ });
58
+ return result.rows;
59
+ };
60
+ const driver = {
61
+ dialect,
62
+ async execute(query, executeOptions) {
63
+ const signal = executeOptions?.signal;
64
+ signal?.throwIfAborted();
65
+ const cancelVia = options?.cancelVia;
66
+ if (signal === undefined || cancelVia === undefined) {
67
+ const ownsPreparedConnection = prepared && !pinned && isPool(client);
68
+ const target = ownsPreparedConnection ? await client.connect() : client;
69
+ try {
70
+ const rows = await executeOn(target, query);
71
+ signal?.throwIfAborted();
72
+ return rows;
73
+ }
74
+ finally {
75
+ if (ownsPreparedConnection)
76
+ release(target);
77
+ }
78
+ }
79
+ const ownsConnection = !pinned && isPool(client);
80
+ const connection = ownsConnection ? await client.connect() : client;
81
+ try {
82
+ signal.throwIfAborted();
83
+ const pid = await backendPid(connection);
84
+ signal.throwIfAborted();
85
+ const removeAbort = forwardAbort(signal, pid, cancelVia);
86
+ try {
87
+ const rows = await executeOn(connection, query);
88
+ signal.throwIfAborted();
89
+ return rows;
90
+ }
91
+ catch (error) {
92
+ if (signal.aborted)
93
+ signal.throwIfAborted();
94
+ throw error;
95
+ }
96
+ finally {
97
+ removeAbort();
98
+ }
99
+ }
100
+ finally {
101
+ if (ownsConnection)
102
+ release(connection);
103
+ }
104
+ },
105
+ ...(pinned || isPool(client)
106
+ ? {
107
+ stream(query, executeOptions) {
108
+ return streamPostgres(client, query, executeOptions, options?.cancelVia, pinned, `zmdb_${(cursorSequence++).toString(36)}`);
109
+ },
110
+ }
111
+ : {}),
112
+ async transaction(run) {
113
+ if (!isPool(client)) {
114
+ return runTransaction(dialect, client, options, preparedStates, run);
115
+ }
116
+ const connection = await client.connect();
117
+ try {
118
+ return await runTransaction(dialect, connection, options, preparedStates, run);
119
+ }
120
+ finally {
121
+ connection.release();
122
+ }
123
+ },
124
+ };
125
+ return driver;
126
+ }
127
+ async function runTransaction(dialect, connection, options, preparedStates, run) {
128
+ const transactionDriver = createPostgresDriver(dialect, connection, options, true, preparedStates);
129
+ await connection.query('BEGIN');
130
+ try {
131
+ const result = await run(transactionDriver);
132
+ await connection.query('COMMIT');
133
+ return result;
134
+ }
135
+ catch (error) {
136
+ await connection.query('ROLLBACK');
137
+ throw error;
138
+ }
139
+ }
140
+ async function backendPid(connection) {
141
+ const result = await connection.query('SELECT pg_backend_pid() AS pid');
142
+ const pid = result.rows[0]?.['pid'];
143
+ if (typeof pid !== 'number' || !Number.isInteger(pid) || pid <= 0) {
144
+ throw new Error('postgresDriver could not read a valid pg_backend_pid()');
145
+ }
146
+ return pid;
147
+ }
148
+ function forwardAbort(signal, pid, cancelVia) {
149
+ let sent = false;
150
+ const cancel = () => {
151
+ if (sent)
152
+ return;
153
+ sent = true;
154
+ void cancelVia.query('SELECT pg_cancel_backend($1)', [pid]).catch(() => { });
155
+ };
156
+ signal.addEventListener('abort', cancel, { once: true });
157
+ if (signal.aborted)
158
+ cancel();
159
+ return () => signal.removeEventListener('abort', cancel);
160
+ }
161
+ function streamPostgres(client, query, options, cancelVia, pinned, cursorName) {
162
+ const batchSize = options?.batchSize ?? 100;
163
+ if (!Number.isSafeInteger(batchSize) || batchSize <= 0) {
164
+ throw new RangeError('batchSize must be a positive safe integer');
165
+ }
166
+ return {
167
+ [Symbol.asyncIterator]() {
168
+ let cleanupFailure;
169
+ const generator = (async function* () {
170
+ const signal = options?.signal;
171
+ signal?.throwIfAborted();
172
+ const ownsConnection = !pinned && isPool(client);
173
+ const connection = ownsConnection ? await client.connect() : client;
174
+ let transactionOpen = false;
175
+ let cursorOpen = false;
176
+ let bodyFailure;
177
+ let removeAbort = () => { };
178
+ try {
179
+ signal?.throwIfAborted();
180
+ const pid = await backendPid(connection);
181
+ if (signal !== undefined && cancelVia !== undefined) {
182
+ removeAbort = forwardAbort(signal, pid, cancelVia);
183
+ }
184
+ signal?.throwIfAborted();
185
+ if (ownsConnection) {
186
+ await connection.query('BEGIN');
187
+ transactionOpen = true;
188
+ }
189
+ await connection.query({
190
+ text: `DECLARE "${cursorName}" NO SCROLL CURSOR FOR ${query.text}`,
191
+ values: query.parameters,
192
+ });
193
+ cursorOpen = true;
194
+ while (true) {
195
+ signal?.throwIfAborted();
196
+ const fetched = await connection.query(`FETCH FORWARD ${batchSize} FROM "${cursorName}"`);
197
+ signal?.throwIfAborted();
198
+ if (fetched.rows.length === 0)
199
+ break;
200
+ for (const row of fetched.rows) {
201
+ signal?.throwIfAborted();
202
+ yield row;
203
+ }
204
+ }
205
+ }
206
+ catch (error) {
207
+ bodyFailure = signal?.aborted === true ? signal.reason : error;
208
+ }
209
+ finally {
210
+ removeAbort();
211
+ if (cursorOpen) {
212
+ try {
213
+ await connection.query(`CLOSE "${cursorName}"`);
214
+ }
215
+ catch (error) {
216
+ cleanupFailure ??= error;
217
+ }
218
+ }
219
+ if (transactionOpen) {
220
+ try {
221
+ await connection.query(bodyFailure === undefined && cleanupFailure === undefined ? 'COMMIT' : 'ROLLBACK');
222
+ }
223
+ catch (error) {
224
+ cleanupFailure ??= error;
225
+ try {
226
+ await connection.query('ROLLBACK');
227
+ }
228
+ catch (rollbackError) {
229
+ cleanupFailure ??= rollbackError;
230
+ }
231
+ }
232
+ }
233
+ if (ownsConnection)
234
+ release(connection);
235
+ }
236
+ if (bodyFailure !== undefined)
237
+ throw bodyFailure;
238
+ if (cleanupFailure !== undefined)
239
+ throw cleanupFailure;
240
+ })();
241
+ return {
242
+ next: () => generator.next(),
243
+ async return() {
244
+ const result = await generator.return(undefined);
245
+ if (cleanupFailure !== undefined)
246
+ throw cleanupFailure;
247
+ return result;
248
+ },
249
+ throw: error => generator.throw(error),
250
+ };
251
+ },
252
+ };
253
+ }
254
+ function release(connection) {
255
+ const method = Reflect.get(connection, 'release');
256
+ if (typeof method === 'function')
257
+ Reflect.apply(method, connection, []);
258
+ }
259
+ function isPool(client) {
260
+ return (typeof client.connect === 'function' &&
261
+ 'totalCount' in client &&
262
+ typeof client.totalCount === 'number' &&
263
+ 'idleCount' in client &&
264
+ typeof client.idleCount === 'number');
265
+ }
266
+ //# sourceMappingURL=driver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsE,MAAM,WAAW,CAAC;AAC/F,OAAO,EAAuC,MAAM,WAAW,CAAC;AAuChE,MAAM,UAAU,oB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OAAO;gBACL,IAAI,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE;gBAC5B,KAAK,CAAC,MAAM;oBACV,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBACjD,IAAI,cAAc,KAAK,SAAS;wBAAE,MAAM,cAAc,CAAC;oBACvD,OAAO,MAAM,CAAC;gBAChB,CAAC;gBACD,KAAK,EAAE,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC;aACvC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,UAAuB;IACtC,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAClD,IAAI,OAAO,MAAM,KAAK,UAAU;QAAE,OAAO,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;AAC1E,CAAC;AAED,SAAS,MAAM,CAAC,MAAmB;IACjC,OAAO,CACL,OAAO,MAAM,CAAC,OAAO,KAAK,UAAU;QACpC,YAAY,IAAI,MAAM;QACtB,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ;QACrC,WAAW,IAAI,MAAM;QACrB,OAAO,MAAM,CAAC,SAAS,KAAK,QAAQ,CACrC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type DatabaseVertical, type TransactionalDriver } from '@zmdb/orm';
2
+ import { type SqlDialect } from '@zmdb/sql';
3
+ import { postgresFamilyDriver, type PgConnection, type PgOptions, type PgQueryable } from './driver.js';
4
+ import { postgresFamilyIntrospector, type PostgresCatalogOverrides } from './introspect.js';
5
+ import { postgresFamilyMigrations, type PostgresMigrationOptions } from './migrations.js';
6
+ export type { PgConnection, PgOptions, PgQueryable, PostgresCatalogOverrides, PostgresMigrationOptions };
7
+ export { postgresFamilyDriver, postgresFamilyIntrospector, postgresFamilyMigrations };
8
+ export { POSTGRES_OUTBOX_TABLE, postgresOutboxMigration, postgresOutboxPendingIndexDdl, postgresOutboxTableDdl, } from './outbox.js';
9
+ export declare const postgresIntrospector: import("@zmdb/sql").Introspector<"postgres">;
10
+ export declare const postgres: SqlDialect<'postgres'>;
11
+ export declare function postgresDriver(client: PgQueryable, options?: PgOptions): TransactionalDriver<'postgres'>;
12
+ export declare const postgresVertical: DatabaseVertical<'postgres', PgQueryable, PgOptions>;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAC5E,OAAO,EAKL,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,oBAAoB,EAAE,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,0BAA0B,EAAE,KAAK,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAE,KAAK,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAE1F,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,CAAC;AACzG,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,CAAC;AACtF,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAyDrB,eAAO,MAAM,oBAAoB,8CAAyC,CAAC;AAE3E,eAAO,MAAM,QAAQ,EAAE,UAAU,CAAC,UAAU,CAe1C,CAAC;AAEH,wBAAgB,cAAc,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,SAAS,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAExG;AAED,eAAO,MAAM,gBAAgB,EAAE,gBAAgB,CAAC,UAAU,EAAE,WAAW,EAAE,SAAS,CAGhF,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,86 @@
1
+ import {} from '@zmdb/orm';
2
+ import { defineSqlDialect, } from '@zmdb/sql';
3
+ import { POSTGRES_TYPES } from './constants.js';
4
+ import { postgresFamilyDriver } from './driver.js';
5
+ import { postgresFamilyIntrospector } from './introspect.js';
6
+ import { postgresFamilyMigrations } from './migrations.js';
7
+ export { postgresFamilyDriver, postgresFamilyIntrospector, postgresFamilyMigrations };
8
+ export { POSTGRES_OUTBOX_TABLE, postgresOutboxMigration, postgresOutboxPendingIndexDdl, postgresOutboxTableDdl, } from './outbox.js';
9
+ const UNMAPPED_OPERATOR_TOKEN = /^(?!.*--)[A-Za-z@<>=!~*&|?-]{1,4}$/;
10
+ const POSTGRES_QUOTE = ['"', '"'];
11
+ Object.freeze(POSTGRES_QUOTE);
12
+ const traits = Object.freeze({
13
+ placeholder: 'numbered',
14
+ quote: POSTGRES_QUOTE,
15
+ paginate: ({ limit, offset }) => {
16
+ let text = '';
17
+ if (limit !== undefined)
18
+ text += ` LIMIT ${limit}`;
19
+ if (offset !== undefined)
20
+ text += ` OFFSET ${offset}`;
21
+ return text;
22
+ },
23
+ paginationRequiresOrder: false,
24
+ rowValueIn: true,
25
+ returning: Object.freeze({
26
+ insert: 'suffix',
27
+ upsert: 'suffix',
28
+ update: 'suffix',
29
+ delete: 'suffix',
30
+ }),
31
+ upsert: 'onConflict',
32
+ fts: 'tsvector',
33
+ concat: 'operator',
34
+ booleanNot: 'not',
35
+ types: POSTGRES_TYPES,
36
+ paramLimit: 60_000,
37
+ retryableCodes: Object.freeze(['40001', '40P01']),
38
+ acceptsOperator: (operator) => operator === '#>' || operator === '#>>' || UNMAPPED_OPERATOR_TOKEN.test(operator),
39
+ functions: true,
40
+ procedures: true,
41
+ tableFunctions: true,
42
+ vectorDistance: true,
43
+ spatialPredicates: true,
44
+ });
45
+ const capabilities = Object.freeze({
46
+ returning: Object.freeze({
47
+ insert: true,
48
+ upsert: true,
49
+ update: true,
50
+ delete: true,
51
+ }),
52
+ transactionalDdl: true,
53
+ schemas: true,
54
+ sequences: true,
55
+ generatedColumns: true,
56
+ partialIndexes: true,
57
+ foreignKeys: true,
58
+ rowLevelSecurity: true,
59
+ streaming: true,
60
+ cancellation: true,
61
+ });
62
+ export const postgresIntrospector = postgresFamilyIntrospector('postgres');
63
+ export const postgres = defineSqlDialect({
64
+ name: 'postgres',
65
+ family: 'postgres',
66
+ telemetrySystem: 'postgresql',
67
+ traits,
68
+ capabilities,
69
+ migrations: postgresFamilyMigrations('postgres'),
70
+ introspector: postgresIntrospector,
71
+ outbox: Object.freeze({
72
+ createTable: 'CREATE TABLE',
73
+ pendingIndex: 'filtered',
74
+ epochLiteral: "'1970-01-01T00:00:00.000Z'",
75
+ createdAtDefault: 'CURRENT_TIMESTAMP',
76
+ boundedTextType: () => 'TEXT',
77
+ }),
78
+ });
79
+ export function postgresDriver(client, options) {
80
+ return postgresFamilyDriver(postgres, client, options);
81
+ }
82
+ export const postgresVertical = Object.freeze({
83
+ dialect: postgres,
84
+ driver: postgresDriver,
85
+ });
86
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmD,MAAM,WAAW,CAAC;AAC5E,OAAO,EACL,gBAAgB,GAKjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAuD,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,0BAA0B,EAAiC,MAAM,iBAAiB,CAAC;AAC5F,OAAO,EAAE,wBAAwB,EAAiC,MAAM,iBAAiB,CAAC;AAG1F,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,wBAAwB,EAAE,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,CAAC,MAAM,CAAC;IAClG,OAAO,EAAE,QAAQ;IACjB,MAAM,EAAE,cAAc;CACvB,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { SchemaSnapshot } from '@zmdb/migrations';
2
+ import type { CatalogSchemaSnapshot, IntrospectionDriver, Introspector, IntrospectOptions } from '@zmdb/migrations/introspect/runtime';
3
+ export interface PostgresCatalogOverrides {
4
+ readonly snapshot?: (parent: (driver: IntrospectionDriver, options?: IntrospectOptions) => Promise<CatalogSchemaSnapshot>, driver: IntrospectionDriver, options?: IntrospectOptions) => Promise<CatalogSchemaSnapshot>;
5
+ readonly normalizeForDrift?: (parent: (snapshot: CatalogSchemaSnapshot, role: 'live' | 'declared') => SchemaSnapshot, snapshot: CatalogSchemaSnapshot, role: 'live' | 'declared') => SchemaSnapshot;
6
+ }
7
+ export declare function postgresFamilyIntrospector<Name extends string>(name: Name, overrides?: PostgresCatalogOverrides): Introspector<Name>;
8
+ //# sourceMappingURL=introspect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"introspect.d.ts","sourceRoot":"","sources":["../src/introspect.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAKV,qBAAqB,EAGrB,mBAAmB,EACnB,YAAY,EACZ,iBAAiB,EAElB,MAAM,qCAAqC,CAAC;AAG7C,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAClB,MAAM,EAAE,CAAC,MAAM,EAAE,mBAAmB,EAAE,OAAO,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,qBAAqB,CAAC,EACpG,MAAM,EAAE,mBAAmB,EAC3B,OAAO,CAAC,EAAE,iBAAiB,KACxB,OAAO,CAAC,qBAAqB,CAAC,CAAC;IACpC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAC3B,MAAM,EAAE,CAAC,QAAQ,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,KAAK,cAAc,EACtF,QAAQ,EAAE,qBAAqB,EAC/B,IAAI,EAAE,MAAM,GAAG,UAAU,KACtB,cAAc,CAAC;CACrB;AAolBD,wBAAgB,0BAA0B,CAAC,IAAI,SAAS,MAAM,EAC5D,IAAI,EAAE,IAAI,EACV,SAAS,GAAE,wBAA6B,GACvC,YAAY,CAAC,IAAI,CAAC,CAkBpB"}