@nextlyhq/adapter-postgres 0.0.2-alpha.7 → 0.0.2-alpha.70

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/dist/index.d.ts CHANGED
@@ -1,80 +1,11 @@
1
- import { DrizzleAdapter } from '@nextlyhq/adapter-drizzle';
2
- import { PostgresAdapterConfig, SqlParam, TransactionContext, TransactionOptions, DatabaseCapabilities, PoolStats, InsertOptions, DatabaseError } from '@nextlyhq/adapter-drizzle/types';
3
- export { AdapterLogger, PoolConfig as AdapterPoolConfig, BaseAdapterConfig, DatabaseCapabilities, DatabaseError, DatabaseErrorKind, DeleteOptions, InsertOptions, JoinSpec, OrderBySpec, PoolStats, PostgresAdapterConfig, SelectOptions, SqlParam, SslConfig, TransactionContext, TransactionOptions, UpdateOptions, UpsertOptions, WhereClause, WhereCondition, WhereOperator } from '@nextlyhq/adapter-drizzle/types';
4
- import { NodePgDatabase } from 'drizzle-orm/node-postgres';
5
-
6
- /**
7
- * @nextlyhq/adapter-postgres
8
- *
9
- * PostgreSQL database adapter for Nextly.
10
- * Extends the base DrizzleAdapter from @nextlyhq/adapter-drizzle to provide
11
- * PostgreSQL-specific functionality.
12
- *
13
- * @remarks
14
- * This adapter uses the `pg` (node-postgres) driver for database connections
15
- * and integrates with Drizzle ORM for type-safe queries.
16
- *
17
- * Features:
18
- * - Connection pooling via pg.Pool
19
- * - Full transaction support with savepoints
20
- * - RETURNING clause support for all CRUD operations
21
- * - PostgreSQL-specific error classification
22
- * - JSONB support
23
- * - Full-text search capabilities
24
- * - Automatic retry for serialization failures and deadlocks
25
- *
26
- * @example
27
- * Simple usage with connection string:
28
- * ```typescript
29
- * import { createPostgresAdapter } from '@nextlyhq/adapter-postgres';
30
- *
31
- * const adapter = createPostgresAdapter({
32
- * url: process.env.DATABASE_URL!,
33
- * });
34
- *
35
- * await adapter.connect();
36
- * ```
37
- *
38
- * @example
39
- * Full configuration:
40
- * ```typescript
41
- * import { createPostgresAdapter } from '@nextlyhq/adapter-postgres';
42
- *
43
- * const adapter = createPostgresAdapter({
44
- * url: process.env.DATABASE_URL!,
45
- * pool: {
46
- * min: 2,
47
- * max: 20,
48
- * idleTimeoutMs: 30000,
49
- * },
50
- * ssl: {
51
- * rejectUnauthorized: true,
52
- * },
53
- * applicationName: 'my-nextly-app',
54
- * });
55
- * ```
56
- *
57
- * @example
58
- * Using the adapter class directly:
59
- * ```typescript
60
- * import { PostgresAdapter } from '@nextlyhq/adapter-postgres';
61
- * import type { PostgresAdapterConfig } from '@nextlyhq/adapter-postgres';
62
- *
63
- * const config: PostgresAdapterConfig = {
64
- * url: process.env.DATABASE_URL!,
65
- * };
66
- *
67
- * const adapter = new PostgresAdapter(config);
68
- * await adapter.connect();
69
- * ```
70
- *
71
- * @packageDocumentation
72
- */
73
-
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 { NodePgDatabase } from "drizzle-orm/node-postgres";
4
+ import { AnyRelations } from "drizzle-orm";
74
5
  /**
75
6
  * Package version.
76
7
  */
77
- declare const VERSION = "0.1.0";
8
+ export declare const VERSION = "0.1.0";
78
9
  /**
79
10
  * PostgreSQL database adapter for Nextly.
80
11
  *
@@ -112,152 +43,192 @@ declare const VERSION = "0.1.0";
112
43
  *
113
44
  * @public
114
45
  */
115
- declare class PostgresAdapter extends DrizzleAdapter {
116
- /**
117
- * The database dialect - always 'postgresql' for this adapter.
118
- */
119
- readonly dialect: "postgresql";
120
- /**
121
- * Adapter configuration.
122
- */
123
- protected readonly config: PostgresAdapterConfig;
124
- /**
125
- * Connection pool instance.
126
- */
127
- private pool;
128
- /**
129
- * Connection state flag.
130
- */
131
- private connected;
132
- /**
133
- * Auto-detected provider (Neon, Supabase, or standard).
134
- * Set during connect() from DATABASE_URL pattern or DB_PROVIDER env var.
135
- */
136
- private detectedProvider;
137
- /**
138
- * Provider-specific connection defaults. Applied as fallbacks when
139
- * user config doesn't specify a value.
140
- */
141
- private providerDefaults;
142
- /**
143
- * Creates a new PostgreSQL adapter instance.
144
- *
145
- * @param config - Adapter configuration
146
- */
147
- constructor(config: PostgresAdapterConfig);
148
- /**
149
- * Establishes a connection to the PostgreSQL database.
150
- *
151
- * @remarks
152
- * This method initializes the connection pool and verifies connectivity
153
- * by executing a simple query. It is idempotent - calling it multiple
154
- * times will not create multiple pools.
155
- *
156
- * @throws {DatabaseError} If connection fails
157
- */
158
- connect(): Promise<void>;
159
- /**
160
- * Closes the database connection and releases all pool resources.
161
- *
162
- * @remarks
163
- * This method is idempotent - calling it multiple times is safe.
164
- * It waits for all checked-out clients to be returned before shutting down.
165
- */
166
- disconnect(): Promise<void>;
167
- /**
168
- * Checks if the adapter is currently connected.
169
- *
170
- * @returns True if connected and pool is available
171
- */
172
- isConnected(): boolean;
173
- /**
174
- * Executes a raw SQL query.
175
- *
176
- * @param sql - SQL statement with $1, $2, ... placeholders
177
- * @param params - Query parameters
178
- * @returns Array of result rows
179
- *
180
- * @throws {DatabaseError} If query execution fails
181
- */
182
- executeQuery<T = unknown>(sql: string, params?: SqlParam[]): Promise<T[]>;
183
- /**
184
- * Executes a callback within a database transaction.
185
- *
186
- * @remarks
187
- * PostgreSQL supports full ACID transactions with savepoints.
188
- * If the callback throws, the transaction is rolled back.
189
- *
190
- * Supports automatic retry for serialization failures (40001) and
191
- * deadlocks (40P01) when `retryCount` is specified in options.
192
- *
193
- * @param callback - Function to execute within the transaction
194
- * @param options - Transaction options (isolation level, timeout, retry)
195
- * @returns The result of the callback
196
- *
197
- * @throws {DatabaseError} If transaction fails after all retries
198
- */
199
- transaction<T>(callback: (ctx: TransactionContext) => Promise<T>, options?: TransactionOptions): Promise<T>;
200
- /**
201
- * Returns the database capabilities for PostgreSQL.
202
- *
203
- * @remarks
204
- * PostgreSQL has the most comprehensive feature set of all supported
205
- * databases, including JSONB, arrays, full-text search, and more.
206
- */
207
- getCapabilities(): DatabaseCapabilities;
208
- /**
209
- * Returns connection pool statistics.
210
- *
211
- * @returns Pool stats or null if not connected
212
- */
213
- getPoolStats(): PoolStats | null;
214
- /**
215
- * Override insertMany for bulk insert optimization.
216
- *
217
- * @remarks
218
- * Uses a single multi-row INSERT statement for better performance
219
- * when inserting multiple records.
220
- */
221
- insertMany<T = unknown>(table: string, data: Record<string, unknown>[], options?: InsertOptions): Promise<T[]>;
222
- /**
223
- * Ensures pool is connected and returns it.
224
- *
225
- * @throws {DatabaseError} If not connected
226
- */
227
- private ensurePool;
228
- /**
229
- * Return the typed Drizzle instance for PostgreSQL.
230
- * Guarded for server-only usage and requires an active connection.
231
- *
232
- * @param schema - Optional schema for relational queries (db.query.*)
233
- * @returns Drizzle ORM instance wrapping the pg pool connection
234
- * @throws {Error} If called in browser or not connected
235
- */
236
- getDrizzle<T = NodePgDatabase<any>>(schema?: Record<string, unknown>): T;
237
- /**
238
- * Builds pg Pool configuration from adapter config.
239
- */
240
- private buildPoolConfig;
241
- /**
242
- * Begins a transaction with the specified options.
243
- */
244
- private beginTransaction;
245
- /**
246
- * Creates a TransactionContext for the given client.
247
- */
248
- private createTransactionContext;
249
- /**
250
- * Classifies a PostgreSQL error into a DatabaseError.
251
- *
252
- * @param error - Original error from pg
253
- * @param sql - SQL statement that caused the error (optional)
254
- * @returns DatabaseError with proper classification
255
- */
256
- private classifyError;
257
- /**
258
- * Override handleQueryError to use PostgreSQL-specific classification.
259
- */
260
- protected handleQueryError(error: unknown, operation: string, table: string): DatabaseError;
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;
261
232
  }
262
233
  /**
263
234
  * Creates a PostgreSQL database adapter instance.
@@ -304,7 +275,7 @@ declare class PostgresAdapter extends DrizzleAdapter {
304
275
  *
305
276
  * @public
306
277
  */
307
- declare function createPostgresAdapter(config: PostgresAdapterConfig): PostgresAdapter;
278
+ export declare function createPostgresAdapter(config: PostgresAdapterConfig$1): PostgresAdapter;
308
279
  /**
309
280
  * Type guard to check if a value is a PostgresAdapter instance.
310
281
  *
@@ -323,6 +294,6 @@ declare function createPostgresAdapter(config: PostgresAdapterConfig): PostgresA
323
294
  *
324
295
  * @public
325
296
  */
326
- declare function isPostgresAdapter(value: unknown): value is PostgresAdapter;
327
-
328
- export { PostgresAdapter, VERSION, createPostgresAdapter, isPostgresAdapter };
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.ts.map