@atscript/db-postgres 0.1.38 → 0.1.40

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.
@@ -0,0 +1,279 @@
1
+ import { t as PostgresPlugin } from "./index-Tl2u3rTo.cjs";
2
+ import { BaseDbAdapter, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDefaultFn, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbUpdateResult, TExistingColumn, TFieldOps, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair } from "@atscript/db";
3
+ import { TMetadataMap } from "@atscript/typescript/utils";
4
+ import * as pg from "pg";
5
+ import { TSqlFragment } from "@atscript/db-sql-tools";
6
+
7
+ //#region src/types.d.ts
8
+ /**
9
+ * Result of a PostgreSQL statement that modifies data (INSERT, UPDATE, DELETE).
10
+ */
11
+ interface TPgRunResult {
12
+ /** Number of rows affected by the statement. */
13
+ affectedRows: number;
14
+ /** Rows returned by a RETURNING clause (empty array when not applicable). */
15
+ rows: Record<string, unknown>[];
16
+ }
17
+ /**
18
+ * Async driver interface for PostgreSQL engines.
19
+ *
20
+ * The driver has two modes of operation:
21
+ * 1. **Pool mode** (default) — each call acquires/releases a connection automatically
22
+ * 2. **Connection mode** (for transactions) — a dedicated connection is acquired
23
+ * and all operations run on it until released
24
+ *
25
+ * Implementations: {@link PgDriver}
26
+ */
27
+ interface TPgDriver {
28
+ /**
29
+ * Execute a SQL statement that modifies data (INSERT, UPDATE, DELETE, DDL).
30
+ * Uses parameterized queries (`$1, $2, ...` placeholders).
31
+ */
32
+ run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
33
+ /**
34
+ * Execute a query and return all matching rows.
35
+ */
36
+ all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
37
+ /**
38
+ * Execute a query and return the first matching row, or null.
39
+ */
40
+ get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
41
+ /**
42
+ * Execute raw SQL without returning results.
43
+ * Used for DDL, SET statements, etc.
44
+ */
45
+ exec(sql: string): Promise<void>;
46
+ /**
47
+ * Acquire a dedicated connection for transaction use.
48
+ * Returns a {@link TPgConnection} that must be released after use.
49
+ */
50
+ getConnection(): Promise<TPgConnection>;
51
+ /**
52
+ * Close the pool / end all connections.
53
+ */
54
+ close(): Promise<void>;
55
+ }
56
+ /**
57
+ * A dedicated connection acquired from the pool.
58
+ * Used for transactions where all operations must run on the same connection.
59
+ */
60
+ interface TPgConnection {
61
+ /** Execute a statement that modifies data. */
62
+ run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
63
+ /** Execute a query and return all matching rows. */
64
+ all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
65
+ /** Execute a query and return the first matching row, or null. */
66
+ get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
67
+ /** Execute raw SQL without returning results. */
68
+ exec(sql: string): Promise<void>;
69
+ /** Release this connection back to the pool. */
70
+ release(): void;
71
+ }
72
+ //#endregion
73
+ //#region src/postgres-adapter.d.ts
74
+ /**
75
+ * PostgreSQL adapter for {@link AtscriptDbTable}.
76
+ *
77
+ * Accepts any {@link TPgDriver} implementation — the actual PostgreSQL driver
78
+ * is fully swappable (pg Pool, custom implementations, etc.).
79
+ *
80
+ * Usage:
81
+ * ```typescript
82
+ * import { PgDriver, PostgresAdapter } from '@atscript/db-postgres'
83
+ * import { DbSpace } from '@atscript/db'
84
+ *
85
+ * const driver = new PgDriver('postgresql://user@localhost:5432/mydb')
86
+ * const space = new DbSpace(() => new PostgresAdapter(driver))
87
+ * const users = space.getTable(UsersType)
88
+ * ```
89
+ */
90
+ declare class PostgresAdapter extends BaseDbAdapter {
91
+ protected readonly driver: TPgDriver;
92
+ supportsColumnModify: boolean;
93
+ private static readonly NATIVE_DEFAULT_FNS;
94
+ private _incrementFields;
95
+ private _autoIncrementStart?;
96
+ /** Physical column names with @db.collate 'nocase'. Used to trigger CITEXT extension. */
97
+ private _nocaseColumns;
98
+ /** Whether citext extension has been provisioned (avoids redundant round-trips). */
99
+ private _citextProvisioned;
100
+ /** Whether the connected PostgreSQL instance has the pgvector extension. */
101
+ private _supportsVector;
102
+ /** Vector fields: physical field name → { dimensions, similarity, indexName }. */
103
+ private _vectorFields;
104
+ /** Default similarity thresholds per vector field (from @db.search.vector.threshold). */
105
+ private _vectorThresholds;
106
+ /** Schema name for queries (null falls through to 'public'). */
107
+ private get _schema();
108
+ constructor(driver: TPgDriver);
109
+ protected _beginTransaction(): Promise<TPgConnection>;
110
+ protected _commitTransaction(state: unknown): Promise<void>;
111
+ protected _rollbackTransaction(state: unknown): Promise<void>;
112
+ /**
113
+ * Returns the active executor: dedicated connection if inside a transaction,
114
+ * otherwise the pool-based driver.
115
+ */
116
+ private _exec;
117
+ /** PostgreSQL enforces FK constraints natively. */
118
+ supportsNativeForeignKeys(): boolean;
119
+ prepareId(id: unknown, _fieldType: unknown): unknown;
120
+ supportsNativeValueDefaults(): boolean;
121
+ nativeDefaultFns(): ReadonlySet<TDbDefaultFn>;
122
+ onBeforeFlatten(_type: unknown): void;
123
+ onAfterFlatten(): void;
124
+ onFieldScanned(field: string, _type: unknown, metadata: TMetadataMap<AtscriptMetadata>): void;
125
+ getDesiredTableOptions(): never[];
126
+ getExistingTableOptions(): Promise<never[]>;
127
+ /**
128
+ * Converts vector fields between JavaScript `number[]` and pgvector text format `[1,2,3]`.
129
+ * The pg driver serializes JS arrays as PostgreSQL array literals `{1,2,3}` which is
130
+ * invalid for the pgvector `vector` type — it expects bracket-delimited `[1,2,3]`.
131
+ */
132
+ formatValue(field: TDbFieldMeta): TValueFormatterPair | undefined;
133
+ /**
134
+ * Wraps an async write operation to catch PostgreSQL constraint errors
135
+ * and rethrow as structured `DbError`.
136
+ *
137
+ * PostgreSQL uses SQLSTATE codes:
138
+ * - 23505 = unique_violation
139
+ * - 23503 = foreign_key_violation
140
+ */
141
+ private _wrapConstraintError;
142
+ private _extractFieldFromConstraint;
143
+ private _mapFkError;
144
+ insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
145
+ insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
146
+ findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
147
+ findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
148
+ count(query: DbQuery): Promise<number>;
149
+ aggregate(query: DbQuery): Promise<Array<Record<string, unknown>>>;
150
+ updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
151
+ updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
152
+ replaceOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
153
+ replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
154
+ deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
155
+ deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
156
+ ensureTable(): Promise<void>;
157
+ private _ensureView;
158
+ getExistingColumns(): Promise<TExistingColumn[]>;
159
+ getExistingColumnsForTable(tableName: string): Promise<TExistingColumn[]>;
160
+ syncColumns(diff: TColumnDiff): Promise<TSyncColumnResult>;
161
+ recreateTable(): Promise<void>;
162
+ afterSyncTable(): Promise<void>;
163
+ /**
164
+ * Resets IDENTITY sequences to MAX(column) so that the next auto-generated
165
+ * value doesn't conflict with existing data. PostgreSQL's GENERATED BY DEFAULT
166
+ * AS IDENTITY does not advance the sequence when rows are inserted with explicit
167
+ * values, so this is needed after data seeding, bulk imports, or recreateTable().
168
+ */
169
+ private _resetIdentitySequences;
170
+ tableExists(): Promise<boolean>;
171
+ dropTable(): Promise<void>;
172
+ dropColumns(columns: string[]): Promise<void>;
173
+ dropTableByName(tableName: string): Promise<void>;
174
+ dropViewByName(viewName: string): Promise<void>;
175
+ renameTable(oldName: string): Promise<void>;
176
+ typeMapper(field: TDbFieldMeta): string;
177
+ syncIndexes(): Promise<void>;
178
+ syncForeignKeys(): Promise<void>;
179
+ dropForeignKeys(fkFieldKeys: string[]): Promise<void>;
180
+ /** Queries information_schema for existing FK constraints. */
181
+ private _getExistingFkConstraints;
182
+ getSearchIndexes(): TSearchIndexInfo[];
183
+ search(text: string, query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
184
+ searchWithCount(text: string, query: DbQuery, indexName?: string): Promise<{
185
+ data: Array<Record<string, unknown>>;
186
+ count: number;
187
+ }>;
188
+ private _buildSearchWhere;
189
+ /** Builds the tsvector SQL expression for a fulltext index's fields. Must match between index DDL and queries. */
190
+ private _buildTsvectorExpr;
191
+ private _getFulltextIndex;
192
+ /**
193
+ * Detects pgvector support by attempting to enable the extension.
194
+ * Idempotent — safe to call multiple times.
195
+ */
196
+ private _detectVectorSupport;
197
+ isVectorSearchable(): boolean;
198
+ vectorSearch(vector: number[], query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
199
+ vectorSearchWithCount(vector: number[], query: DbQuery, indexName?: string): Promise<{
200
+ data: Array<Record<string, unknown>>;
201
+ count: number;
202
+ }>;
203
+ /** Resolves vector field and computes shared context for vector search SQL builders. */
204
+ private _prepareVectorSearch;
205
+ private _buildVectorSearchQuery;
206
+ private _buildVectorSearchCountQuery;
207
+ /** Resolves threshold: query-time $threshold > schema-level @db.search.vector.threshold. */
208
+ private _resolveVectorThreshold;
209
+ }
210
+ //#endregion
211
+ //#region src/pg-driver.d.ts
212
+ /**
213
+ * {@link TPgDriver} implementation backed by `pg` (node-postgres).
214
+ *
215
+ * Accepts a connection URI string, a `pg.PoolConfig` object, or a pre-created
216
+ * `pg.Pool` instance.
217
+ *
218
+ * ```typescript
219
+ * import { PgDriver } from '@atscript/db-postgres'
220
+ *
221
+ * // Connection URI
222
+ * const driver = new PgDriver('postgresql://user:pass@localhost:5432/mydb')
223
+ *
224
+ * // Pool options
225
+ * const driver = new PgDriver({
226
+ * host: 'localhost',
227
+ * user: 'postgres',
228
+ * database: 'mydb',
229
+ * max: 10,
230
+ * })
231
+ *
232
+ * // Pre-created pool
233
+ * import pg from 'pg'
234
+ * const pool = new pg.Pool({ connectionString: '...' })
235
+ * const driver = new PgDriver(pool)
236
+ * ```
237
+ *
238
+ * Requires `pg` to be installed:
239
+ * ```bash
240
+ * pnpm add pg
241
+ * ```
242
+ */
243
+ declare class PgDriver implements TPgDriver {
244
+ private pool;
245
+ private poolInit;
246
+ constructor(poolOrConfig: string | pg.Pool | pg.PoolConfig);
247
+ private getPool;
248
+ run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
249
+ all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
250
+ get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
251
+ exec(sql: string): Promise<void>;
252
+ getConnection(): Promise<TPgConnection>;
253
+ close(): Promise<void>;
254
+ }
255
+ //#endregion
256
+ //#region src/filter-builder.d.ts
257
+ /**
258
+ * Translates a filter expression into a parameterized PostgreSQL WHERE clause.
259
+ *
260
+ * Note: The returned fragment uses `?` placeholders (not `$N`).
261
+ * Finalization to `$N` happens when the fragment is consumed by a DML builder
262
+ * (buildSelect, buildUpdate, etc.) via the dialect's `paramPlaceholder`.
263
+ *
264
+ * Case-insensitive columns (`@db.collate 'nocase'`) are handled by CITEXT
265
+ * column type at the storage level — no query-side wrapping needed.
266
+ */
267
+ declare function buildWhere(filter: FilterExpr): TSqlFragment;
268
+ //#endregion
269
+ //#region src/index.d.ts
270
+ /**
271
+ * Creates a {@link DbSpace} backed by a PostgreSQL connection pool.
272
+ *
273
+ * @param uri - PostgreSQL connection URI (e.g., `postgresql://user@localhost:5432/mydb`)
274
+ * @param options - Additional pool options passed to pg.
275
+ * @returns A `DbSpace` that creates `PostgresAdapter` instances per table.
276
+ */
277
+ declare function createAdapter(uri: string, options?: Record<string, unknown>): DbSpace;
278
+ //#endregion
279
+ export { PgDriver, PostgresAdapter, PostgresPlugin, type TPgConnection, type TPgDriver, type TPgRunResult, type TSqlFragment, buildWhere, createAdapter };
@@ -0,0 +1,279 @@
1
+ import { t as PostgresPlugin } from "./index-HFavdjnf.mjs";
2
+ import { BaseDbAdapter, DbQuery, DbSpace, FilterExpr, TColumnDiff, TDbDefaultFn, TDbDeleteResult, TDbFieldMeta, TDbInsertManyResult, TDbInsertResult, TDbUpdateResult, TExistingColumn, TFieldOps, TSearchIndexInfo, TSyncColumnResult, TValueFormatterPair } from "@atscript/db";
3
+ import { TSqlFragment } from "@atscript/db-sql-tools";
4
+ import * as pg from "pg";
5
+ import { TMetadataMap } from "@atscript/typescript/utils";
6
+
7
+ //#region src/types.d.ts
8
+ /**
9
+ * Result of a PostgreSQL statement that modifies data (INSERT, UPDATE, DELETE).
10
+ */
11
+ interface TPgRunResult {
12
+ /** Number of rows affected by the statement. */
13
+ affectedRows: number;
14
+ /** Rows returned by a RETURNING clause (empty array when not applicable). */
15
+ rows: Record<string, unknown>[];
16
+ }
17
+ /**
18
+ * Async driver interface for PostgreSQL engines.
19
+ *
20
+ * The driver has two modes of operation:
21
+ * 1. **Pool mode** (default) — each call acquires/releases a connection automatically
22
+ * 2. **Connection mode** (for transactions) — a dedicated connection is acquired
23
+ * and all operations run on it until released
24
+ *
25
+ * Implementations: {@link PgDriver}
26
+ */
27
+ interface TPgDriver {
28
+ /**
29
+ * Execute a SQL statement that modifies data (INSERT, UPDATE, DELETE, DDL).
30
+ * Uses parameterized queries (`$1, $2, ...` placeholders).
31
+ */
32
+ run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
33
+ /**
34
+ * Execute a query and return all matching rows.
35
+ */
36
+ all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
37
+ /**
38
+ * Execute a query and return the first matching row, or null.
39
+ */
40
+ get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
41
+ /**
42
+ * Execute raw SQL without returning results.
43
+ * Used for DDL, SET statements, etc.
44
+ */
45
+ exec(sql: string): Promise<void>;
46
+ /**
47
+ * Acquire a dedicated connection for transaction use.
48
+ * Returns a {@link TPgConnection} that must be released after use.
49
+ */
50
+ getConnection(): Promise<TPgConnection>;
51
+ /**
52
+ * Close the pool / end all connections.
53
+ */
54
+ close(): Promise<void>;
55
+ }
56
+ /**
57
+ * A dedicated connection acquired from the pool.
58
+ * Used for transactions where all operations must run on the same connection.
59
+ */
60
+ interface TPgConnection {
61
+ /** Execute a statement that modifies data. */
62
+ run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
63
+ /** Execute a query and return all matching rows. */
64
+ all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
65
+ /** Execute a query and return the first matching row, or null. */
66
+ get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
67
+ /** Execute raw SQL without returning results. */
68
+ exec(sql: string): Promise<void>;
69
+ /** Release this connection back to the pool. */
70
+ release(): void;
71
+ }
72
+ //#endregion
73
+ //#region src/postgres-adapter.d.ts
74
+ /**
75
+ * PostgreSQL adapter for {@link AtscriptDbTable}.
76
+ *
77
+ * Accepts any {@link TPgDriver} implementation — the actual PostgreSQL driver
78
+ * is fully swappable (pg Pool, custom implementations, etc.).
79
+ *
80
+ * Usage:
81
+ * ```typescript
82
+ * import { PgDriver, PostgresAdapter } from '@atscript/db-postgres'
83
+ * import { DbSpace } from '@atscript/db'
84
+ *
85
+ * const driver = new PgDriver('postgresql://user@localhost:5432/mydb')
86
+ * const space = new DbSpace(() => new PostgresAdapter(driver))
87
+ * const users = space.getTable(UsersType)
88
+ * ```
89
+ */
90
+ declare class PostgresAdapter extends BaseDbAdapter {
91
+ protected readonly driver: TPgDriver;
92
+ supportsColumnModify: boolean;
93
+ private static readonly NATIVE_DEFAULT_FNS;
94
+ private _incrementFields;
95
+ private _autoIncrementStart?;
96
+ /** Physical column names with @db.collate 'nocase'. Used to trigger CITEXT extension. */
97
+ private _nocaseColumns;
98
+ /** Whether citext extension has been provisioned (avoids redundant round-trips). */
99
+ private _citextProvisioned;
100
+ /** Whether the connected PostgreSQL instance has the pgvector extension. */
101
+ private _supportsVector;
102
+ /** Vector fields: physical field name → { dimensions, similarity, indexName }. */
103
+ private _vectorFields;
104
+ /** Default similarity thresholds per vector field (from @db.search.vector.threshold). */
105
+ private _vectorThresholds;
106
+ /** Schema name for queries (null falls through to 'public'). */
107
+ private get _schema();
108
+ constructor(driver: TPgDriver);
109
+ protected _beginTransaction(): Promise<TPgConnection>;
110
+ protected _commitTransaction(state: unknown): Promise<void>;
111
+ protected _rollbackTransaction(state: unknown): Promise<void>;
112
+ /**
113
+ * Returns the active executor: dedicated connection if inside a transaction,
114
+ * otherwise the pool-based driver.
115
+ */
116
+ private _exec;
117
+ /** PostgreSQL enforces FK constraints natively. */
118
+ supportsNativeForeignKeys(): boolean;
119
+ prepareId(id: unknown, _fieldType: unknown): unknown;
120
+ supportsNativeValueDefaults(): boolean;
121
+ nativeDefaultFns(): ReadonlySet<TDbDefaultFn>;
122
+ onBeforeFlatten(_type: unknown): void;
123
+ onAfterFlatten(): void;
124
+ onFieldScanned(field: string, _type: unknown, metadata: TMetadataMap<AtscriptMetadata>): void;
125
+ getDesiredTableOptions(): never[];
126
+ getExistingTableOptions(): Promise<never[]>;
127
+ /**
128
+ * Converts vector fields between JavaScript `number[]` and pgvector text format `[1,2,3]`.
129
+ * The pg driver serializes JS arrays as PostgreSQL array literals `{1,2,3}` which is
130
+ * invalid for the pgvector `vector` type — it expects bracket-delimited `[1,2,3]`.
131
+ */
132
+ formatValue(field: TDbFieldMeta): TValueFormatterPair | undefined;
133
+ /**
134
+ * Wraps an async write operation to catch PostgreSQL constraint errors
135
+ * and rethrow as structured `DbError`.
136
+ *
137
+ * PostgreSQL uses SQLSTATE codes:
138
+ * - 23505 = unique_violation
139
+ * - 23503 = foreign_key_violation
140
+ */
141
+ private _wrapConstraintError;
142
+ private _extractFieldFromConstraint;
143
+ private _mapFkError;
144
+ insertOne(data: Record<string, unknown>): Promise<TDbInsertResult>;
145
+ insertMany(data: Array<Record<string, unknown>>): Promise<TDbInsertManyResult>;
146
+ findOne(query: DbQuery): Promise<Record<string, unknown> | null>;
147
+ findMany(query: DbQuery): Promise<Array<Record<string, unknown>>>;
148
+ count(query: DbQuery): Promise<number>;
149
+ aggregate(query: DbQuery): Promise<Array<Record<string, unknown>>>;
150
+ updateOne(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
151
+ updateMany(filter: FilterExpr, data: Record<string, unknown>, ops?: TFieldOps): Promise<TDbUpdateResult>;
152
+ replaceOne(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
153
+ replaceMany(filter: FilterExpr, data: Record<string, unknown>): Promise<TDbUpdateResult>;
154
+ deleteOne(filter: FilterExpr): Promise<TDbDeleteResult>;
155
+ deleteMany(filter: FilterExpr): Promise<TDbDeleteResult>;
156
+ ensureTable(): Promise<void>;
157
+ private _ensureView;
158
+ getExistingColumns(): Promise<TExistingColumn[]>;
159
+ getExistingColumnsForTable(tableName: string): Promise<TExistingColumn[]>;
160
+ syncColumns(diff: TColumnDiff): Promise<TSyncColumnResult>;
161
+ recreateTable(): Promise<void>;
162
+ afterSyncTable(): Promise<void>;
163
+ /**
164
+ * Resets IDENTITY sequences to MAX(column) so that the next auto-generated
165
+ * value doesn't conflict with existing data. PostgreSQL's GENERATED BY DEFAULT
166
+ * AS IDENTITY does not advance the sequence when rows are inserted with explicit
167
+ * values, so this is needed after data seeding, bulk imports, or recreateTable().
168
+ */
169
+ private _resetIdentitySequences;
170
+ tableExists(): Promise<boolean>;
171
+ dropTable(): Promise<void>;
172
+ dropColumns(columns: string[]): Promise<void>;
173
+ dropTableByName(tableName: string): Promise<void>;
174
+ dropViewByName(viewName: string): Promise<void>;
175
+ renameTable(oldName: string): Promise<void>;
176
+ typeMapper(field: TDbFieldMeta): string;
177
+ syncIndexes(): Promise<void>;
178
+ syncForeignKeys(): Promise<void>;
179
+ dropForeignKeys(fkFieldKeys: string[]): Promise<void>;
180
+ /** Queries information_schema for existing FK constraints. */
181
+ private _getExistingFkConstraints;
182
+ getSearchIndexes(): TSearchIndexInfo[];
183
+ search(text: string, query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
184
+ searchWithCount(text: string, query: DbQuery, indexName?: string): Promise<{
185
+ data: Array<Record<string, unknown>>;
186
+ count: number;
187
+ }>;
188
+ private _buildSearchWhere;
189
+ /** Builds the tsvector SQL expression for a fulltext index's fields. Must match between index DDL and queries. */
190
+ private _buildTsvectorExpr;
191
+ private _getFulltextIndex;
192
+ /**
193
+ * Detects pgvector support by attempting to enable the extension.
194
+ * Idempotent — safe to call multiple times.
195
+ */
196
+ private _detectVectorSupport;
197
+ isVectorSearchable(): boolean;
198
+ vectorSearch(vector: number[], query: DbQuery, indexName?: string): Promise<Array<Record<string, unknown>>>;
199
+ vectorSearchWithCount(vector: number[], query: DbQuery, indexName?: string): Promise<{
200
+ data: Array<Record<string, unknown>>;
201
+ count: number;
202
+ }>;
203
+ /** Resolves vector field and computes shared context for vector search SQL builders. */
204
+ private _prepareVectorSearch;
205
+ private _buildVectorSearchQuery;
206
+ private _buildVectorSearchCountQuery;
207
+ /** Resolves threshold: query-time $threshold > schema-level @db.search.vector.threshold. */
208
+ private _resolveVectorThreshold;
209
+ }
210
+ //#endregion
211
+ //#region src/pg-driver.d.ts
212
+ /**
213
+ * {@link TPgDriver} implementation backed by `pg` (node-postgres).
214
+ *
215
+ * Accepts a connection URI string, a `pg.PoolConfig` object, or a pre-created
216
+ * `pg.Pool` instance.
217
+ *
218
+ * ```typescript
219
+ * import { PgDriver } from '@atscript/db-postgres'
220
+ *
221
+ * // Connection URI
222
+ * const driver = new PgDriver('postgresql://user:pass@localhost:5432/mydb')
223
+ *
224
+ * // Pool options
225
+ * const driver = new PgDriver({
226
+ * host: 'localhost',
227
+ * user: 'postgres',
228
+ * database: 'mydb',
229
+ * max: 10,
230
+ * })
231
+ *
232
+ * // Pre-created pool
233
+ * import pg from 'pg'
234
+ * const pool = new pg.Pool({ connectionString: '...' })
235
+ * const driver = new PgDriver(pool)
236
+ * ```
237
+ *
238
+ * Requires `pg` to be installed:
239
+ * ```bash
240
+ * pnpm add pg
241
+ * ```
242
+ */
243
+ declare class PgDriver implements TPgDriver {
244
+ private pool;
245
+ private poolInit;
246
+ constructor(poolOrConfig: string | pg.Pool | pg.PoolConfig);
247
+ private getPool;
248
+ run(sql: string, params?: unknown[]): Promise<TPgRunResult>;
249
+ all<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
250
+ get<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T | null>;
251
+ exec(sql: string): Promise<void>;
252
+ getConnection(): Promise<TPgConnection>;
253
+ close(): Promise<void>;
254
+ }
255
+ //#endregion
256
+ //#region src/filter-builder.d.ts
257
+ /**
258
+ * Translates a filter expression into a parameterized PostgreSQL WHERE clause.
259
+ *
260
+ * Note: The returned fragment uses `?` placeholders (not `$N`).
261
+ * Finalization to `$N` happens when the fragment is consumed by a DML builder
262
+ * (buildSelect, buildUpdate, etc.) via the dialect's `paramPlaceholder`.
263
+ *
264
+ * Case-insensitive columns (`@db.collate 'nocase'`) are handled by CITEXT
265
+ * column type at the storage level — no query-side wrapping needed.
266
+ */
267
+ declare function buildWhere(filter: FilterExpr): TSqlFragment;
268
+ //#endregion
269
+ //#region src/index.d.ts
270
+ /**
271
+ * Creates a {@link DbSpace} backed by a PostgreSQL connection pool.
272
+ *
273
+ * @param uri - PostgreSQL connection URI (e.g., `postgresql://user@localhost:5432/mydb`)
274
+ * @param options - Additional pool options passed to pg.
275
+ * @returns A `DbSpace` that creates `PostgresAdapter` instances per table.
276
+ */
277
+ declare function createAdapter(uri: string, options?: Record<string, unknown>): DbSpace;
278
+ //#endregion
279
+ export { PgDriver, PostgresAdapter, PostgresPlugin, type TPgConnection, type TPgDriver, type TPgRunResult, type TSqlFragment, buildWhere, createAdapter };