@nextlyhq/adapter-postgres 0.0.2-alpha.68 → 0.0.2-alpha.69
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 +5 -5
- package/dist/index.cjs +933 -823
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +195 -265
- package/dist/index.d.ts +195 -265
- package/dist/index.mjs +910 -801
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -16
package/dist/index.d.cts
CHANGED
|
@@ -1,81 +1,11 @@
|
|
|
1
|
-
import { DrizzleAdapter } from
|
|
2
|
-
import { PostgresAdapterConfig, SqlParam, TransactionContext, TransactionOptions,
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @nextlyhq/adapter-postgres
|
|
9
|
-
*
|
|
10
|
-
* PostgreSQL database adapter for Nextly.
|
|
11
|
-
* Extends the base DrizzleAdapter from @nextlyhq/adapter-drizzle to provide
|
|
12
|
-
* PostgreSQL-specific functionality.
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* This adapter uses the `pg` (node-postgres) driver for database connections
|
|
16
|
-
* and integrates with Drizzle ORM for type-safe queries.
|
|
17
|
-
*
|
|
18
|
-
* Features:
|
|
19
|
-
* - Connection pooling via pg.Pool
|
|
20
|
-
* - Full transaction support with savepoints
|
|
21
|
-
* - RETURNING clause support for all CRUD operations
|
|
22
|
-
* - PostgreSQL-specific error classification
|
|
23
|
-
* - JSONB support
|
|
24
|
-
* - Full-text search capabilities
|
|
25
|
-
* - Automatic retry for serialization failures and deadlocks
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* Simple usage with connection string:
|
|
29
|
-
* ```typescript
|
|
30
|
-
* import { createPostgresAdapter } from '@nextlyhq/adapter-postgres';
|
|
31
|
-
*
|
|
32
|
-
* const adapter = createPostgresAdapter({
|
|
33
|
-
* url: process.env.DATABASE_URL!,
|
|
34
|
-
* });
|
|
35
|
-
*
|
|
36
|
-
* await adapter.connect();
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* Full configuration:
|
|
41
|
-
* ```typescript
|
|
42
|
-
* import { createPostgresAdapter } from '@nextlyhq/adapter-postgres';
|
|
43
|
-
*
|
|
44
|
-
* const adapter = createPostgresAdapter({
|
|
45
|
-
* url: process.env.DATABASE_URL!,
|
|
46
|
-
* pool: {
|
|
47
|
-
* min: 2,
|
|
48
|
-
* max: 20,
|
|
49
|
-
* idleTimeoutMs: 30000,
|
|
50
|
-
* },
|
|
51
|
-
* ssl: {
|
|
52
|
-
* rejectUnauthorized: true,
|
|
53
|
-
* },
|
|
54
|
-
* applicationName: 'my-nextly-app',
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* Using the adapter class directly:
|
|
60
|
-
* ```typescript
|
|
61
|
-
* import { PostgresAdapter } from '@nextlyhq/adapter-postgres';
|
|
62
|
-
* import type { PostgresAdapterConfig } from '@nextlyhq/adapter-postgres';
|
|
63
|
-
*
|
|
64
|
-
* const config: PostgresAdapterConfig = {
|
|
65
|
-
* url: process.env.DATABASE_URL!,
|
|
66
|
-
* };
|
|
67
|
-
*
|
|
68
|
-
* const adapter = new PostgresAdapter(config);
|
|
69
|
-
* await adapter.connect();
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
* @packageDocumentation
|
|
73
|
-
*/
|
|
74
|
-
|
|
1
|
+
import { DrizzleAdapter } from "@nextlyhq/adapter-drizzle";
|
|
2
|
+
import { AdapterLogger, BaseAdapterConfig, DatabaseCapabilities, DatabaseCapabilities as DatabaseCapabilities$1, DatabaseError, DatabaseError as DatabaseError$1, DatabaseErrorKind, DeleteOptions, InsertOptions, InsertOptions as InsertOptions$1, JoinSpec, OrderBySpec, PoolConfig as AdapterPoolConfig, PoolStats, PoolStats as PoolStats$1, PostgresAdapterConfig, PostgresAdapterConfig as PostgresAdapterConfig$1, SelectOptions, SqlParam, SqlParam as SqlParam$1, SslConfig, TransactionContext, TransactionContext as TransactionContext$1, TransactionOptions, TransactionOptions as TransactionOptions$1, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator } from "@nextlyhq/adapter-drizzle/types";
|
|
3
|
+
import { AnyRelations } from "drizzle-orm";
|
|
4
|
+
import { NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
75
5
|
/**
|
|
76
6
|
* Package version.
|
|
77
7
|
*/
|
|
78
|
-
declare const VERSION = "0.1.0";
|
|
8
|
+
export declare const VERSION = "0.1.0";
|
|
79
9
|
/**
|
|
80
10
|
* PostgreSQL database adapter for Nextly.
|
|
81
11
|
*
|
|
@@ -113,192 +43,192 @@ declare const VERSION = "0.1.0";
|
|
|
113
43
|
*
|
|
114
44
|
* @public
|
|
115
45
|
*/
|
|
116
|
-
declare class PostgresAdapter extends DrizzleAdapter {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
46
|
+
export declare class PostgresAdapter extends DrizzleAdapter {
|
|
47
|
+
private drizzleByRelations;
|
|
48
|
+
private drizzleBare;
|
|
49
|
+
/**
|
|
50
|
+
* The database dialect - always 'postgresql' for this adapter.
|
|
51
|
+
*/
|
|
52
|
+
readonly dialect: "postgresql";
|
|
53
|
+
/**
|
|
54
|
+
* Adapter configuration.
|
|
55
|
+
*/
|
|
56
|
+
protected readonly config: PostgresAdapterConfig$1;
|
|
57
|
+
/**
|
|
58
|
+
* Connection pool instance.
|
|
59
|
+
*/
|
|
60
|
+
private pool;
|
|
61
|
+
/**
|
|
62
|
+
* Connection state flag.
|
|
63
|
+
*/
|
|
64
|
+
private connected;
|
|
65
|
+
/**
|
|
66
|
+
* Auto-detected provider (Neon, Supabase, or standard).
|
|
67
|
+
* Set during connect() from DATABASE_URL pattern or DB_PROVIDER env var.
|
|
68
|
+
*/
|
|
69
|
+
private detectedProvider;
|
|
70
|
+
/**
|
|
71
|
+
* Provider-specific connection defaults. Applied as fallbacks when
|
|
72
|
+
* user config doesn't specify a value.
|
|
73
|
+
*/
|
|
74
|
+
private providerDefaults;
|
|
75
|
+
/**
|
|
76
|
+
* Creates a new PostgreSQL adapter instance.
|
|
77
|
+
*
|
|
78
|
+
* @param config - Adapter configuration
|
|
79
|
+
*/
|
|
80
|
+
constructor(config: PostgresAdapterConfig$1);
|
|
81
|
+
/**
|
|
82
|
+
* Establishes a connection to the PostgreSQL database.
|
|
83
|
+
*
|
|
84
|
+
* @remarks
|
|
85
|
+
* This method initializes the connection pool and verifies connectivity
|
|
86
|
+
* by executing a simple query. It is idempotent - calling it multiple
|
|
87
|
+
* times will not create multiple pools.
|
|
88
|
+
*
|
|
89
|
+
* @throws {DatabaseError} If connection fails
|
|
90
|
+
*/
|
|
91
|
+
connect(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Closes the database connection and releases all pool resources.
|
|
94
|
+
*
|
|
95
|
+
* @remarks
|
|
96
|
+
* This method is idempotent - calling it multiple times is safe.
|
|
97
|
+
* It waits for all checked-out clients to be returned before shutting down.
|
|
98
|
+
*/
|
|
99
|
+
disconnect(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Checks if the adapter is currently connected.
|
|
102
|
+
*
|
|
103
|
+
* @returns True if connected and pool is available
|
|
104
|
+
*/
|
|
105
|
+
override isConnected(): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Executes a raw SQL query.
|
|
108
|
+
*
|
|
109
|
+
* @param sql - SQL statement with $1, $2, ... placeholders
|
|
110
|
+
* @param params - Query parameters
|
|
111
|
+
* @returns Array of result rows
|
|
112
|
+
*
|
|
113
|
+
* @throws {DatabaseError} If query execution fails
|
|
114
|
+
*/
|
|
115
|
+
executeQuery<T = unknown>(sql: string, params?: SqlParam$1[]): Promise<T[]>;
|
|
116
|
+
/**
|
|
117
|
+
* Executes a callback within a database transaction.
|
|
118
|
+
*
|
|
119
|
+
* @remarks
|
|
120
|
+
* PostgreSQL supports full ACID transactions with savepoints.
|
|
121
|
+
* If the callback throws, the transaction is rolled back.
|
|
122
|
+
*
|
|
123
|
+
* Supports automatic retry for serialization failures (40001) and
|
|
124
|
+
* deadlocks (40P01) when `retryCount` is specified in options.
|
|
125
|
+
*
|
|
126
|
+
* An error carrying the Nextly application brand is neither retried nor
|
|
127
|
+
* classified: it is the application refusing the write, so it arrives at the
|
|
128
|
+
* caller as it was thrown. Retrying it would repeat work whose verdict has
|
|
129
|
+
* already been given. Every other error, including an unbranded one raised by
|
|
130
|
+
* the callback, is retried when it is a serialization failure or deadlock and
|
|
131
|
+
* classified on the way out.
|
|
132
|
+
*
|
|
133
|
+
* @param callback - Function to execute within the transaction
|
|
134
|
+
* @param options - Transaction options (isolation level, timeout, retry)
|
|
135
|
+
* @returns The result of the callback
|
|
136
|
+
*
|
|
137
|
+
* @throws {DatabaseError} If the transaction itself fails after all retries,
|
|
138
|
+
* or if the callback threw an error that does not carry the application brand
|
|
139
|
+
* @throws The callback's own error, unchanged, when it carries that brand
|
|
140
|
+
*/
|
|
141
|
+
transaction<T>(callback: (ctx: TransactionContext$1) => Promise<T>, options?: TransactionOptions$1): Promise<T>;
|
|
142
|
+
/** The attempts `transaction` makes, each on a connection of its own. */
|
|
143
|
+
private runTransactionAttempts;
|
|
144
|
+
/**
|
|
145
|
+
* Returns the database capabilities for PostgreSQL.
|
|
146
|
+
*
|
|
147
|
+
* @remarks
|
|
148
|
+
* PostgreSQL has the most comprehensive feature set of all supported
|
|
149
|
+
* databases, including JSONB, arrays, full-text search, and more.
|
|
150
|
+
*/
|
|
151
|
+
getCapabilities(): DatabaseCapabilities$1;
|
|
152
|
+
/**
|
|
153
|
+
* The schema set as `search_path` on every pooled connection.
|
|
154
|
+
*
|
|
155
|
+
* @remarks
|
|
156
|
+
* Answers with the same test `buildPoolConfig` applies, so an empty string
|
|
157
|
+
* reports `undefined` exactly as it sets no `search_path`: the value
|
|
158
|
+
* reported is the one the connections actually use.
|
|
159
|
+
*
|
|
160
|
+
* @returns The configured schema, or `undefined` when the server's default
|
|
161
|
+
* `search_path` applies
|
|
162
|
+
*/
|
|
163
|
+
getConfiguredSchema(): string | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Returns connection pool statistics.
|
|
166
|
+
*
|
|
167
|
+
* @returns Pool stats or null if not connected
|
|
168
|
+
*/
|
|
169
|
+
override getPoolStats(): PoolStats$1 | null;
|
|
170
|
+
/**
|
|
171
|
+
* Override insertMany for bulk insert optimization.
|
|
172
|
+
*
|
|
173
|
+
* @remarks
|
|
174
|
+
* Uses a single multi-row INSERT statement for better performance
|
|
175
|
+
* when inserting multiple records.
|
|
176
|
+
*/
|
|
177
|
+
override insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions$1): Promise<T[]>;
|
|
178
|
+
/**
|
|
179
|
+
* Ensures pool is connected and returns it.
|
|
180
|
+
*
|
|
181
|
+
* @throws {DatabaseError} If not connected
|
|
182
|
+
*/
|
|
183
|
+
private ensurePool;
|
|
184
|
+
/**
|
|
185
|
+
* Return the typed Drizzle instance for PostgreSQL.
|
|
186
|
+
* Guarded for server-only usage and requires an active connection.
|
|
187
|
+
*
|
|
188
|
+
* @param schema - Optional schema for relational queries (db.query.*)
|
|
189
|
+
* @returns Drizzle ORM instance wrapping the pg pool connection
|
|
190
|
+
* @throws {Error} If called in browser or not connected
|
|
191
|
+
*/
|
|
192
|
+
getDrizzle<T = NodePgDatabase<AnyRelations>>(relations?: AnyRelations): T;
|
|
193
|
+
/**
|
|
194
|
+
* A Drizzle handle on the pool, for `getDrizzle`.
|
|
195
|
+
*
|
|
196
|
+
* Its `transaction` runs on a client this adapter checks out and returns
|
|
197
|
+
* itself (`pinDrizzleTransactions`): node-postgres destroys a client
|
|
198
|
+
* released with `true`, which is what happens when no ROLLBACK could be
|
|
199
|
+
* confirmed on it. And it counts for `transactionOpenInFlow`, as the
|
|
200
|
+
* adapter's does.
|
|
201
|
+
*/
|
|
202
|
+
private poolDrizzle;
|
|
203
|
+
/**
|
|
204
|
+
* Builds pg Pool configuration from adapter config.
|
|
205
|
+
*/
|
|
206
|
+
private buildPoolConfig;
|
|
207
|
+
/**
|
|
208
|
+
* Begins a transaction with the specified options.
|
|
209
|
+
*/
|
|
210
|
+
private beginTransaction;
|
|
211
|
+
/**
|
|
212
|
+
* Creates a TransactionContext for the given client.
|
|
213
|
+
*/
|
|
214
|
+
/**
|
|
215
|
+
* The RETURNING entries that spell each date column's wall clock out as
|
|
216
|
+
* text, one per alias `dateWallClockAliases` chose. `to_char` renders the
|
|
217
|
+
* stored value without a zone, which is the only form node-postgres cannot
|
|
218
|
+
* shift on the way back.
|
|
219
|
+
*/
|
|
220
|
+
private wallClockSpelling;
|
|
221
|
+
/** A table-level `primaryKey({ columns })`, read through the PostgreSQL table config. */
|
|
222
|
+
protected override compositePrimaryKey(tableObj: Record<string, unknown>): object[];
|
|
223
|
+
private createTransactionContext;
|
|
224
|
+
/**
|
|
225
|
+
* Classifies a PostgreSQL error into a DatabaseError.
|
|
226
|
+
*
|
|
227
|
+
* @param error - Original error from pg
|
|
228
|
+
* @param sql - SQL statement that caused the error (optional)
|
|
229
|
+
* @returns DatabaseError with proper classification
|
|
230
|
+
*/
|
|
231
|
+
protected override classifyError(error: unknown, sql?: string): DatabaseError$1;
|
|
302
232
|
}
|
|
303
233
|
/**
|
|
304
234
|
* Creates a PostgreSQL database adapter instance.
|
|
@@ -345,7 +275,7 @@ declare class PostgresAdapter extends DrizzleAdapter {
|
|
|
345
275
|
*
|
|
346
276
|
* @public
|
|
347
277
|
*/
|
|
348
|
-
declare function createPostgresAdapter(config: PostgresAdapterConfig): PostgresAdapter;
|
|
278
|
+
export declare function createPostgresAdapter(config: PostgresAdapterConfig$1): PostgresAdapter;
|
|
349
279
|
/**
|
|
350
280
|
* Type guard to check if a value is a PostgresAdapter instance.
|
|
351
281
|
*
|
|
@@ -364,6 +294,6 @@ declare function createPostgresAdapter(config: PostgresAdapterConfig): PostgresA
|
|
|
364
294
|
*
|
|
365
295
|
* @public
|
|
366
296
|
*/
|
|
367
|
-
declare function isPostgresAdapter(value: unknown): value is PostgresAdapter;
|
|
368
|
-
|
|
369
|
-
|
|
297
|
+
export declare function isPostgresAdapter(value: unknown): value is PostgresAdapter;
|
|
298
|
+
export type { AdapterLogger, AdapterPoolConfig, BaseAdapterConfig, DatabaseCapabilities, DatabaseError, DatabaseErrorKind, DeleteOptions, InsertOptions, JoinSpec, OrderBySpec, PoolStats, PostgresAdapterConfig, SelectOptions, SqlParam, SslConfig, TransactionContext, TransactionOptions, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator };
|
|
299
|
+
//# sourceMappingURL=index.d.cts.map
|