@agentuity/drizzle 1.0.18 → 1.0.20
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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/postgres.d.ts +26 -7
- package/dist/postgres.d.ts.map +1 -1
- package/dist/postgres.js +90 -44
- package/dist/postgres.js.map +1 -1
- package/dist/types.d.ts +33 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/index.ts +1 -1
- package/src/postgres.ts +167 -39
- package/src/types.ts +44 -1
package/dist/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
* @packageDocumentation
|
|
32
32
|
*/
|
|
33
33
|
export { createPostgresDrizzle, drizzle } from './postgres.ts';
|
|
34
|
-
export type { PostgresDrizzleConfig, PostgresDrizzle } from './types.ts';
|
|
34
|
+
export type { PostgresDrizzleConfig, PostgresDrizzle, PostgresDrizzlePg } from './types.ts';
|
|
35
35
|
export { postgres, PostgresClient, type CallablePostgresClient, type PostgresConfig, type ReconnectConfig, type ConnectionStats, type TLSConfig, type TransactionOptions, type ReserveOptions, } from '@agentuity/postgres';
|
|
36
36
|
export { sql, eq, and, or, not, desc, asc, gt, gte, lt, lte, ne, isNull, isNotNull, inArray, notInArray, between, like, ilike, relations, } from 'drizzle-orm';
|
|
37
37
|
export type { BunSQLDatabase, BunSQLPreparedQuery, BunSQLSession, BunSQLTransaction, } from 'drizzle-orm/bun-sql';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG/D,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,qBAAqB,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAG/D,YAAY,EAAE,qBAAqB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG5F,OAAO,EACN,QAAQ,EACR,cAAc,EACd,KAAK,sBAAsB,EAC3B,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,SAAS,EACd,KAAK,kBAAkB,EACvB,KAAK,cAAc,GACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,IAAI,EACJ,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,GAAG,EACH,EAAE,EACF,MAAM,EACN,SAAS,EACT,OAAO,EACP,UAAU,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,SAAS,GACT,MAAM,aAAa,CAAC;AAGrB,YAAY,EACX,cAAc,EACd,mBAAmB,EACnB,aAAa,EACb,iBAAiB,GACjB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACN,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,EAEN,MAAM,EACN,SAAS,EACT,OAAO,EACP,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,UAAU,EACV,IAAI,EACJ,eAAe,EACf,IAAI,EACJ,OAAO,EACP,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,OAAO,EACP,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,MAAM,EACN,QAAQ,EACR,WAAW,EACX,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,OAAO,EAEP,UAAU,EACV,UAAU,EACV,MAAM,EACN,WAAW,EACX,KAAK,EACL,KAAK,GACL,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC"}
|
package/dist/postgres.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { SQL as BunSQL, type SQL as BunSQLClient, type SQLOptions } from 'bun';
|
|
|
2
2
|
import { type BunSQLDatabase } from 'drizzle-orm/bun-sql';
|
|
3
3
|
import type { DrizzleConfig } from 'drizzle-orm';
|
|
4
4
|
import { type CallablePostgresClient, type PostgresConfig } from '@agentuity/postgres';
|
|
5
|
-
import type { PostgresDrizzleConfig, PostgresDrizzle } from './types.ts';
|
|
5
|
+
import type { PostgresDrizzleConfig, PostgresDrizzle, PostgresDrizzlePg } from './types.ts';
|
|
6
6
|
/**
|
|
7
7
|
* Resolves the PostgreSQL client configuration from Drizzle config options.
|
|
8
8
|
*
|
|
@@ -56,19 +56,22 @@ export declare const drizzle: typeof _drizzle & {
|
|
|
56
56
|
* import { createPostgresDrizzle } from '@agentuity/drizzle';
|
|
57
57
|
* import * as schema from './schema';
|
|
58
58
|
*
|
|
59
|
-
* // Basic usage with DATABASE_URL
|
|
60
|
-
* const { db, close } = createPostgresDrizzle({ schema });
|
|
59
|
+
* // Basic usage with DATABASE_URL (defaults to pg driver with resilient pool)
|
|
60
|
+
* const { db, client, close } = createPostgresDrizzle({ schema });
|
|
61
61
|
*
|
|
62
62
|
* // Query with type safety
|
|
63
63
|
* const users = await db.select().from(schema.users);
|
|
64
64
|
*
|
|
65
|
+
* // Access connection stats from the resilient pool
|
|
66
|
+
* console.log(client.stats);
|
|
67
|
+
*
|
|
65
68
|
* // Clean up when done
|
|
66
69
|
* await close();
|
|
67
70
|
* ```
|
|
68
71
|
*
|
|
69
72
|
* @example
|
|
70
73
|
* ```typescript
|
|
71
|
-
* // With custom connection configuration
|
|
74
|
+
* // With custom connection and reconnection configuration
|
|
72
75
|
* const { db, client, close } = createPostgresDrizzle({
|
|
73
76
|
* connectionString: 'postgres://user:pass@localhost:5432/mydb',
|
|
74
77
|
* schema,
|
|
@@ -79,11 +82,27 @@ export declare const drizzle: typeof _drizzle & {
|
|
|
79
82
|
* },
|
|
80
83
|
* onReconnected: () => console.log('Database reconnected'),
|
|
81
84
|
* });
|
|
85
|
+
* ```
|
|
82
86
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* // Opt-in to Bun's native SQL driver for maximum performance
|
|
90
|
+
* const { db, client, close } = createPostgresDrizzle({
|
|
91
|
+
* url: process.env.DATABASE_URL,
|
|
92
|
+
* schema,
|
|
93
|
+
* driver: 'bun-sql',
|
|
94
|
+
* });
|
|
85
95
|
* ```
|
|
86
96
|
*/
|
|
87
|
-
|
|
97
|
+
/**
|
|
98
|
+
* Creates a Drizzle ORM instance using Bun's native SQL driver.
|
|
99
|
+
*/
|
|
100
|
+
export declare function createPostgresDrizzle<TSchema extends Record<string, unknown> = Record<string, never>>(config: PostgresDrizzleConfig<TSchema> & {
|
|
101
|
+
driver: 'bun-sql';
|
|
102
|
+
}): PostgresDrizzle<TSchema>;
|
|
103
|
+
/**
|
|
104
|
+
* Creates a Drizzle ORM instance using the pg (node-postgres) driver (default).
|
|
105
|
+
*/
|
|
106
|
+
export declare function createPostgresDrizzle<TSchema extends Record<string, unknown> = Record<string, never>>(config?: PostgresDrizzleConfig<TSchema>): PostgresDrizzlePg<TSchema>;
|
|
88
107
|
export {};
|
|
89
108
|
//# sourceMappingURL=postgres.d.ts.map
|
package/dist/postgres.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,MAAM,EAAE,KAAK,GAAG,IAAI,YAAY,EAAE,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAC/E,OAAO,EAA8B,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"post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AAE,GAAG;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC,GAC3F,cAAc,CAAC,OAAO,CAAC,GAAG;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAwBhD;kBAhCQ,QAAQ;eAkCA,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,mCAC9C,aAAa,CAAC,OAAO,CAAC,KAC7B,cAAc,CAAC,OAAO,CAAC,GAAG;QAAE,OAAO,EAAE,4CAA4C,CAAA;KAAE;;AAStF,eAAO,MAAM,OAAO,EAAe,OAAO,QAAQ,GAAG;IACpD,IAAI,EAAE,OAAO,QAAQ,CAAC,IAAI,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9D,MAAM,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;AAE5F;;GAEG;AACH,wBAAgB,qBAAqB,CACpC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAC9D,MAAM,CAAC,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC"}
|
package/dist/postgres.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { drizzle as upstreamDrizzle } from 'drizzle-orm/bun-sql';
|
|
2
|
+
import { drizzle as nodePgDrizzle, } from 'drizzle-orm/node-postgres';
|
|
2
3
|
import { isConfig } from 'drizzle-orm/utils';
|
|
3
|
-
import {
|
|
4
|
+
import { StructuredError } from '@agentuity/core';
|
|
5
|
+
import { postgres, PostgresPool, isMutationStatement, createThenable, } from '@agentuity/postgres';
|
|
6
|
+
const DrizzleConfigError = StructuredError('DrizzleConfigError');
|
|
4
7
|
/**
|
|
5
8
|
* Resolves the PostgreSQL client configuration from Drizzle config options.
|
|
6
9
|
*
|
|
@@ -239,51 +242,94 @@ _drizzle.mock = (config) => {
|
|
|
239
242
|
return db;
|
|
240
243
|
};
|
|
241
244
|
export const drizzle = _drizzle;
|
|
245
|
+
// Implementation signature
|
|
246
|
+
export function createPostgresDrizzle(config) {
|
|
247
|
+
// bun-sql driver path (opt-in)
|
|
248
|
+
if (config?.driver === 'bun-sql') {
|
|
249
|
+
return createBunSqlDrizzle(config);
|
|
250
|
+
}
|
|
251
|
+
// Default: pg (node-postgres) driver backed by resilient PostgresPool
|
|
252
|
+
return createPgDrizzle(config);
|
|
253
|
+
}
|
|
242
254
|
/**
|
|
243
|
-
* Creates a Drizzle
|
|
244
|
-
*
|
|
245
|
-
* This function combines the power of Drizzle ORM with @agentuity/postgres's
|
|
246
|
-
* automatic reconnection capabilities. The underlying connection will
|
|
247
|
-
* automatically reconnect with exponential backoff if the connection is lost.
|
|
248
|
-
*
|
|
249
|
-
* @template TSchema - The Drizzle schema type for type-safe queries
|
|
250
|
-
* @param config - Configuration options for the database connection
|
|
251
|
-
* @returns An object containing the Drizzle instance, underlying client, and close function
|
|
252
|
-
*
|
|
253
|
-
* @example
|
|
254
|
-
* ```typescript
|
|
255
|
-
* import { createPostgresDrizzle } from '@agentuity/drizzle';
|
|
256
|
-
* import * as schema from './schema';
|
|
257
|
-
*
|
|
258
|
-
* // Basic usage with DATABASE_URL
|
|
259
|
-
* const { db, close } = createPostgresDrizzle({ schema });
|
|
260
|
-
*
|
|
261
|
-
* // Query with type safety
|
|
262
|
-
* const users = await db.select().from(schema.users);
|
|
263
|
-
*
|
|
264
|
-
* // Clean up when done
|
|
265
|
-
* await close();
|
|
266
|
-
* ```
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* // With custom connection configuration
|
|
271
|
-
* const { db, client, close } = createPostgresDrizzle({
|
|
272
|
-
* connectionString: 'postgres://user:pass@localhost:5432/mydb',
|
|
273
|
-
* schema,
|
|
274
|
-
* logger: true,
|
|
275
|
-
* reconnect: {
|
|
276
|
-
* maxAttempts: 5,
|
|
277
|
-
* initialDelayMs: 100,
|
|
278
|
-
* },
|
|
279
|
-
* onReconnected: () => console.log('Database reconnected'),
|
|
280
|
-
* });
|
|
281
|
-
*
|
|
282
|
-
* // Access connection stats
|
|
283
|
-
* console.log(client.stats);
|
|
284
|
-
* ```
|
|
255
|
+
* Creates a Drizzle instance using the pg (node-postgres) driver
|
|
256
|
+
* backed by a resilient PostgresPool with automatic reconnection.
|
|
285
257
|
*/
|
|
286
|
-
|
|
258
|
+
function createPgDrizzle(config) {
|
|
259
|
+
// Build PostgresPool config from drizzle config.
|
|
260
|
+
// PoolConfig extends pg.PoolConfig so it supports both connectionString
|
|
261
|
+
// and individual fields (host, port, database, user, password).
|
|
262
|
+
const poolConfig = {
|
|
263
|
+
reconnect: config?.reconnect,
|
|
264
|
+
onreconnected: config?.onReconnected,
|
|
265
|
+
};
|
|
266
|
+
// Resolve connection: URL string takes priority, then individual fields
|
|
267
|
+
const url = config?.url ??
|
|
268
|
+
config?.connectionString ??
|
|
269
|
+
config?.connection?.url ??
|
|
270
|
+
process.env.DATABASE_URL;
|
|
271
|
+
if (url) {
|
|
272
|
+
poolConfig.connectionString = url;
|
|
273
|
+
}
|
|
274
|
+
else if (config?.connection) {
|
|
275
|
+
// Map PostgresConfig fields to pg.PoolConfig fields
|
|
276
|
+
const conn = config.connection;
|
|
277
|
+
if (conn.hostname)
|
|
278
|
+
poolConfig.host = conn.hostname;
|
|
279
|
+
if (conn.port)
|
|
280
|
+
poolConfig.port = conn.port;
|
|
281
|
+
if (conn.database)
|
|
282
|
+
poolConfig.database = conn.database;
|
|
283
|
+
if (conn.username)
|
|
284
|
+
poolConfig.user = conn.username;
|
|
285
|
+
if (conn.password)
|
|
286
|
+
poolConfig.password = conn.password;
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
throw new DrizzleConfigError({
|
|
290
|
+
message: 'createPostgresDrizzle(): No connection configuration found. ' +
|
|
291
|
+
'Provide url, connectionString, connection.url, connection fields, or set DATABASE_URL.',
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
// Create resilient pool
|
|
295
|
+
const pool = new PostgresPool(poolConfig);
|
|
296
|
+
// Pass the pool to drizzle-orm/node-postgres.
|
|
297
|
+
// PostgresPool implements the same query()/connect() interface as pg.Pool
|
|
298
|
+
// but with automatic retry and reconnection. Drizzle calls pool.query()
|
|
299
|
+
// for each operation, so all queries go through our resilience layer.
|
|
300
|
+
const db = nodePgDrizzle(pool, {
|
|
301
|
+
schema: config?.schema,
|
|
302
|
+
logger: config?.logger,
|
|
303
|
+
});
|
|
304
|
+
// Fire onConnect callback once the pool is warm
|
|
305
|
+
if (config?.onConnect) {
|
|
306
|
+
pool
|
|
307
|
+
.waitForConnection()
|
|
308
|
+
.then(() => {
|
|
309
|
+
try {
|
|
310
|
+
config.onConnect();
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
// Swallow synchronous exceptions from onConnect callback
|
|
314
|
+
}
|
|
315
|
+
})
|
|
316
|
+
.catch(() => {
|
|
317
|
+
// Connection failed — onConnect is not invoked
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
db,
|
|
322
|
+
client: pool,
|
|
323
|
+
close: async () => {
|
|
324
|
+
await pool.close();
|
|
325
|
+
},
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Creates a Drizzle instance using Bun's native SQL driver
|
|
330
|
+
* with the resilient SQL proxy for automatic reconnection.
|
|
331
|
+
*/
|
|
332
|
+
function createBunSqlDrizzle(config) {
|
|
287
333
|
// Resolve the postgres client configuration
|
|
288
334
|
const clientConfig = resolvePostgresClientConfig(config);
|
|
289
335
|
// Create the postgres client
|
package/dist/postgres.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAuB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"postgres.js","sourceRoot":"","sources":["../src/postgres.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAuB,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACN,OAAO,IAAI,aAAa,GAGxB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACN,QAAQ,EACR,YAAY,EACZ,mBAAmB,EACnB,cAAc,GAId,MAAM,qBAAqB,CAAC;AAG7B,MAAM,kBAAkB,GAAG,eAAe,CAAC,oBAAoB,CAAC,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,UAAU,2BAA2B,CAEzC,MAAuC;IACxC,oEAAoE;IACpE,MAAM,YAAY,GAAmB,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAExF,mCAAmC;IACnC,IAAI,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;YACjB,YAAY,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QAC/B,CAAC;aAAM,IAAI,MAAM,EAAE,gBAAgB,EAAE,CAAC;YACrC,YAAY,CAAC,GAAG,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAC5C,CAAC;aAAM,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;YACrC,YAA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ACtB,CAAC;KACD,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Logger as DrizzleLogger } from 'drizzle-orm';
|
|
2
2
|
import type { BunSQLDatabase } from 'drizzle-orm/bun-sql';
|
|
3
|
-
import type {
|
|
3
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
+
import type { PostgresConfig, ReconnectConfig, CallablePostgresClient, PostgresPool } from '@agentuity/postgres';
|
|
4
5
|
/**
|
|
5
6
|
* Configuration options for creating a PostgreSQL Drizzle instance.
|
|
6
7
|
*
|
|
@@ -76,6 +77,21 @@ export interface PostgresDrizzleConfig<TSchema extends Record<string, unknown> =
|
|
|
76
77
|
* Callback invoked when the connection is re-established after a disconnect.
|
|
77
78
|
*/
|
|
78
79
|
onReconnected?: () => void;
|
|
80
|
+
/**
|
|
81
|
+
* The database driver to use.
|
|
82
|
+
*
|
|
83
|
+
* - `'pg'` (default): Uses the `pg` (node-postgres) driver via `drizzle-orm/node-postgres`
|
|
84
|
+
* backed by a resilient {@link PostgresPool} with automatic reconnection.
|
|
85
|
+
* This is the recommended driver for all use cases.
|
|
86
|
+
*
|
|
87
|
+
* - `'bun-sql'`: Uses Bun's native SQL driver via `drizzle-orm/bun-sql`.
|
|
88
|
+
* May offer slightly better performance but has known parameter binding
|
|
89
|
+
* issues with some libraries (e.g. Better Auth).
|
|
90
|
+
* See: https://github.com/agentuity/sdk/issues/1030
|
|
91
|
+
*
|
|
92
|
+
* @default 'pg'
|
|
93
|
+
*/
|
|
94
|
+
driver?: 'pg' | 'bun-sql';
|
|
79
95
|
}
|
|
80
96
|
/**
|
|
81
97
|
* The result of creating a PostgreSQL Drizzle instance.
|
|
@@ -97,4 +113,20 @@ export interface PostgresDrizzle<TSchema extends Record<string, unknown> = Recor
|
|
|
97
113
|
*/
|
|
98
114
|
close: () => Promise<void>;
|
|
99
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* The result of creating a PostgreSQL Drizzle instance with the 'pg' driver.
|
|
118
|
+
*
|
|
119
|
+
* @template TSchema - The Drizzle schema type
|
|
120
|
+
*/
|
|
121
|
+
export interface PostgresDrizzlePg<TSchema extends Record<string, unknown> = Record<string, never>> {
|
|
122
|
+
/** The Drizzle database instance (node-postgres backed). */
|
|
123
|
+
db: NodePgDatabase<TSchema>;
|
|
124
|
+
/**
|
|
125
|
+
* The underlying resilient PostgreSQL pool with reconnection support.
|
|
126
|
+
* Can be used for raw queries or accessing connection state.
|
|
127
|
+
*/
|
|
128
|
+
client: PostgresPool;
|
|
129
|
+
/** Closes the underlying pool and releases resources. */
|
|
130
|
+
close: () => Promise<void>;
|
|
131
|
+
}
|
|
100
132
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,KAAK,EACX,cAAc,EACd,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,MAAM,qBAAqB,CAAC;AAE7B;;;;GAIG;AACH,MAAM,WAAW,qBAAqB,CACrC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,E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MAAM,EAAE,YAAY,CAAC;IAErB,yDAAyD;IACzD,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentuity/drizzle",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"author": "Agentuity employees and contributors",
|
|
6
6
|
"type": "module",
|
|
@@ -41,12 +41,13 @@
|
|
|
41
41
|
"prepublishOnly": "bun run clean && bun run build"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@agentuity/
|
|
44
|
+
"@agentuity/core": "1.0.20",
|
|
45
|
+
"@agentuity/postgres": "1.0.20",
|
|
45
46
|
"drizzle-orm": "^0.45.0",
|
|
46
47
|
"better-auth": "^1.4.9"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
|
-
"@agentuity/test-utils": "1.0.
|
|
50
|
+
"@agentuity/test-utils": "1.0.20",
|
|
50
51
|
"@types/bun": "latest",
|
|
51
52
|
"bun-types": "latest",
|
|
52
53
|
"typescript": "^5.9.0"
|
package/src/index.ts
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
export { createPostgresDrizzle, drizzle } from './postgres.ts';
|
|
36
36
|
|
|
37
37
|
// Types
|
|
38
|
-
export type { PostgresDrizzleConfig, PostgresDrizzle } from './types.ts';
|
|
38
|
+
export type { PostgresDrizzleConfig, PostgresDrizzle, PostgresDrizzlePg } from './types.ts';
|
|
39
39
|
|
|
40
40
|
// Re-export from @agentuity/postgres for convenience
|
|
41
41
|
export {
|
package/src/postgres.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
import { SQL as BunSQL, type SQL as BunSQLClient, type SQLOptions } from 'bun';
|
|
2
2
|
import { drizzle as upstreamDrizzle, type BunSQLDatabase } from 'drizzle-orm/bun-sql';
|
|
3
|
+
import {
|
|
4
|
+
drizzle as nodePgDrizzle,
|
|
5
|
+
type NodePgDatabase,
|
|
6
|
+
type NodePgClient,
|
|
7
|
+
} from 'drizzle-orm/node-postgres';
|
|
3
8
|
import type { DrizzleConfig } from 'drizzle-orm';
|
|
4
9
|
import { isConfig } from 'drizzle-orm/utils';
|
|
10
|
+
import { StructuredError } from '@agentuity/core';
|
|
5
11
|
import {
|
|
6
12
|
postgres,
|
|
13
|
+
PostgresPool,
|
|
7
14
|
isMutationStatement,
|
|
8
15
|
createThenable,
|
|
9
16
|
type CallablePostgresClient,
|
|
10
17
|
type PostgresConfig,
|
|
18
|
+
type PoolConfig,
|
|
11
19
|
} from '@agentuity/postgres';
|
|
12
|
-
import type { PostgresDrizzleConfig, PostgresDrizzle } from './types.ts';
|
|
20
|
+
import type { PostgresDrizzleConfig, PostgresDrizzle, PostgresDrizzlePg } from './types.ts';
|
|
21
|
+
|
|
22
|
+
const DrizzleConfigError = StructuredError('DrizzleConfigError');
|
|
13
23
|
|
|
14
24
|
/**
|
|
15
25
|
* Resolves the PostgreSQL client configuration from Drizzle config options.
|
|
@@ -99,40 +109,40 @@ export function createResilientSQLProxy(
|
|
|
99
109
|
// double-applied updates, or repeated delete side effects.
|
|
100
110
|
const isMutation = isMutationStatement(query);
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
112
|
+
if (isMutation) {
|
|
113
|
+
// Mutation statements are wrapped in a transaction and retried
|
|
114
|
+
// via executeWithRetry. This is safe because PostgreSQL
|
|
115
|
+
// guarantees that uncommitted transactions are automatically
|
|
116
|
+
// rolled back when the connection drops. If the connection
|
|
117
|
+
// fails before COMMIT completes, no changes are applied, and
|
|
118
|
+
// the retry starts a fresh transaction on the new connection.
|
|
119
|
+
//
|
|
120
|
+
// We use sql.begin(callback) instead of manual BEGIN/COMMIT
|
|
121
|
+
// because Bun's SQL driver requires it for pool-safe
|
|
122
|
+
// transactions (ERR_POSTGRES_UNSAFE_TRANSACTION when max > 1).
|
|
123
|
+
// sql.begin() reserves a specific connection, auto-COMMITs on
|
|
124
|
+
// success, and auto-ROLLBACKs on error.
|
|
125
|
+
//
|
|
126
|
+
// NOTE: If the connection drops after the server processes
|
|
127
|
+
// COMMIT but before the client receives the response, the
|
|
128
|
+
// changes ARE committed. A retry would then apply them again.
|
|
129
|
+
// This window is extremely small (< 1ms typically) and is an
|
|
130
|
+
// inherent limitation of any retry-based approach without
|
|
131
|
+
// application-level idempotency (e.g., unique constraints
|
|
132
|
+
// with ON CONFLICT for INSERTs).
|
|
133
|
+
// See: https://github.com/agentuity/sdk/issues/911
|
|
134
|
+
const makeTransactionalExecutor = (useValues: boolean) =>
|
|
135
|
+
client.executeWithRetry(async () => {
|
|
136
|
+
// Re-resolve raw inside retry to get post-reconnect instance
|
|
137
|
+
const currentRaw = client.raw;
|
|
138
|
+
return currentRaw.begin(async (tx) => {
|
|
139
|
+
const q = tx.unsafe(query, params);
|
|
140
|
+
return useValues ? await q.values() : await q;
|
|
141
|
+
});
|
|
131
142
|
});
|
|
132
|
-
});
|
|
133
143
|
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
return createThenable(makeTransactionalExecutor);
|
|
145
|
+
}
|
|
136
146
|
|
|
137
147
|
const makeExecutor = (useValues: boolean) =>
|
|
138
148
|
client.executeWithRetry(async () => {
|
|
@@ -342,19 +352,22 @@ export const drizzle = _drizzle as typeof _drizzle & {
|
|
|
342
352
|
* import { createPostgresDrizzle } from '@agentuity/drizzle';
|
|
343
353
|
* import * as schema from './schema';
|
|
344
354
|
*
|
|
345
|
-
* // Basic usage with DATABASE_URL
|
|
346
|
-
* const { db, close } = createPostgresDrizzle({ schema });
|
|
355
|
+
* // Basic usage with DATABASE_URL (defaults to pg driver with resilient pool)
|
|
356
|
+
* const { db, client, close } = createPostgresDrizzle({ schema });
|
|
347
357
|
*
|
|
348
358
|
* // Query with type safety
|
|
349
359
|
* const users = await db.select().from(schema.users);
|
|
350
360
|
*
|
|
361
|
+
* // Access connection stats from the resilient pool
|
|
362
|
+
* console.log(client.stats);
|
|
363
|
+
*
|
|
351
364
|
* // Clean up when done
|
|
352
365
|
* await close();
|
|
353
366
|
* ```
|
|
354
367
|
*
|
|
355
368
|
* @example
|
|
356
369
|
* ```typescript
|
|
357
|
-
* // With custom connection configuration
|
|
370
|
+
* // With custom connection and reconnection configuration
|
|
358
371
|
* const { db, client, close } = createPostgresDrizzle({
|
|
359
372
|
* connectionString: 'postgres://user:pass@localhost:5432/mydb',
|
|
360
373
|
* schema,
|
|
@@ -365,14 +378,129 @@ export const drizzle = _drizzle as typeof _drizzle & {
|
|
|
365
378
|
* },
|
|
366
379
|
* onReconnected: () => console.log('Database reconnected'),
|
|
367
380
|
* });
|
|
381
|
+
* ```
|
|
368
382
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* // Opt-in to Bun's native SQL driver for maximum performance
|
|
386
|
+
* const { db, client, close } = createPostgresDrizzle({
|
|
387
|
+
* url: process.env.DATABASE_URL,
|
|
388
|
+
* schema,
|
|
389
|
+
* driver: 'bun-sql',
|
|
390
|
+
* });
|
|
371
391
|
* ```
|
|
372
392
|
*/
|
|
393
|
+
/**
|
|
394
|
+
* Creates a Drizzle ORM instance using Bun's native SQL driver.
|
|
395
|
+
*/
|
|
373
396
|
export function createPostgresDrizzle<
|
|
374
397
|
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
375
|
-
>(config
|
|
398
|
+
>(config: PostgresDrizzleConfig<TSchema> & { driver: 'bun-sql' }): PostgresDrizzle<TSchema>;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Creates a Drizzle ORM instance using the pg (node-postgres) driver (default).
|
|
402
|
+
*/
|
|
403
|
+
export function createPostgresDrizzle<
|
|
404
|
+
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
405
|
+
>(config?: PostgresDrizzleConfig<TSchema>): PostgresDrizzlePg<TSchema>;
|
|
406
|
+
|
|
407
|
+
// Implementation signature
|
|
408
|
+
export function createPostgresDrizzle<
|
|
409
|
+
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
410
|
+
>(config?: PostgresDrizzleConfig<TSchema>): PostgresDrizzle<TSchema> | PostgresDrizzlePg<TSchema> {
|
|
411
|
+
// bun-sql driver path (opt-in)
|
|
412
|
+
if (config?.driver === 'bun-sql') {
|
|
413
|
+
return createBunSqlDrizzle(config);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Default: pg (node-postgres) driver backed by resilient PostgresPool
|
|
417
|
+
return createPgDrizzle(config);
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Creates a Drizzle instance using the pg (node-postgres) driver
|
|
422
|
+
* backed by a resilient PostgresPool with automatic reconnection.
|
|
423
|
+
*/
|
|
424
|
+
function createPgDrizzle<TSchema extends Record<string, unknown> = Record<string, never>>(
|
|
425
|
+
config?: PostgresDrizzleConfig<TSchema>
|
|
426
|
+
): PostgresDrizzlePg<TSchema> {
|
|
427
|
+
// Build PostgresPool config from drizzle config.
|
|
428
|
+
// PoolConfig extends pg.PoolConfig so it supports both connectionString
|
|
429
|
+
// and individual fields (host, port, database, user, password).
|
|
430
|
+
const poolConfig: PoolConfig = {
|
|
431
|
+
reconnect: config?.reconnect,
|
|
432
|
+
onreconnected: config?.onReconnected,
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// Resolve connection: URL string takes priority, then individual fields
|
|
436
|
+
const url =
|
|
437
|
+
config?.url ??
|
|
438
|
+
config?.connectionString ??
|
|
439
|
+
config?.connection?.url ??
|
|
440
|
+
process.env.DATABASE_URL;
|
|
441
|
+
|
|
442
|
+
if (url) {
|
|
443
|
+
poolConfig.connectionString = url;
|
|
444
|
+
} else if (config?.connection) {
|
|
445
|
+
// Map PostgresConfig fields to pg.PoolConfig fields
|
|
446
|
+
const conn = config.connection;
|
|
447
|
+
if (conn.hostname) poolConfig.host = conn.hostname;
|
|
448
|
+
if (conn.port) poolConfig.port = conn.port;
|
|
449
|
+
if (conn.database) poolConfig.database = conn.database;
|
|
450
|
+
if (conn.username) poolConfig.user = conn.username;
|
|
451
|
+
if (conn.password) poolConfig.password = conn.password;
|
|
452
|
+
} else {
|
|
453
|
+
throw new DrizzleConfigError({
|
|
454
|
+
message:
|
|
455
|
+
'createPostgresDrizzle(): No connection configuration found. ' +
|
|
456
|
+
'Provide url, connectionString, connection.url, connection fields, or set DATABASE_URL.',
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// Create resilient pool
|
|
461
|
+
const pool = new PostgresPool(poolConfig);
|
|
462
|
+
|
|
463
|
+
// Pass the pool to drizzle-orm/node-postgres.
|
|
464
|
+
// PostgresPool implements the same query()/connect() interface as pg.Pool
|
|
465
|
+
// but with automatic retry and reconnection. Drizzle calls pool.query()
|
|
466
|
+
// for each operation, so all queries go through our resilience layer.
|
|
467
|
+
const db = nodePgDrizzle(pool as unknown as NodePgClient, {
|
|
468
|
+
schema: config?.schema,
|
|
469
|
+
logger: config?.logger,
|
|
470
|
+
}) as NodePgDatabase<TSchema>;
|
|
471
|
+
|
|
472
|
+
// Fire onConnect callback once the pool is warm
|
|
473
|
+
if (config?.onConnect) {
|
|
474
|
+
pool
|
|
475
|
+
.waitForConnection()
|
|
476
|
+
.then(() => {
|
|
477
|
+
try {
|
|
478
|
+
config.onConnect!();
|
|
479
|
+
} catch {
|
|
480
|
+
// Swallow synchronous exceptions from onConnect callback
|
|
481
|
+
}
|
|
482
|
+
})
|
|
483
|
+
.catch(() => {
|
|
484
|
+
// Connection failed — onConnect is not invoked
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return {
|
|
489
|
+
db,
|
|
490
|
+
client: pool,
|
|
491
|
+
close: async () => {
|
|
492
|
+
await pool.close();
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Creates a Drizzle instance using Bun's native SQL driver
|
|
499
|
+
* with the resilient SQL proxy for automatic reconnection.
|
|
500
|
+
*/
|
|
501
|
+
function createBunSqlDrizzle<TSchema extends Record<string, unknown> = Record<string, never>>(
|
|
502
|
+
config?: PostgresDrizzleConfig<TSchema>
|
|
503
|
+
): PostgresDrizzle<TSchema> {
|
|
376
504
|
// Resolve the postgres client configuration
|
|
377
505
|
const clientConfig = resolvePostgresClientConfig(config);
|
|
378
506
|
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Logger as DrizzleLogger } from 'drizzle-orm';
|
|
2
2
|
import type { BunSQLDatabase } from 'drizzle-orm/bun-sql';
|
|
3
|
-
import type {
|
|
3
|
+
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
4
|
+
import type {
|
|
5
|
+
PostgresConfig,
|
|
6
|
+
ReconnectConfig,
|
|
7
|
+
CallablePostgresClient,
|
|
8
|
+
PostgresPool,
|
|
9
|
+
} from '@agentuity/postgres';
|
|
4
10
|
|
|
5
11
|
/**
|
|
6
12
|
* Configuration options for creating a PostgreSQL Drizzle instance.
|
|
@@ -89,6 +95,22 @@ export interface PostgresDrizzleConfig<
|
|
|
89
95
|
* Callback invoked when the connection is re-established after a disconnect.
|
|
90
96
|
*/
|
|
91
97
|
onReconnected?: () => void;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The database driver to use.
|
|
101
|
+
*
|
|
102
|
+
* - `'pg'` (default): Uses the `pg` (node-postgres) driver via `drizzle-orm/node-postgres`
|
|
103
|
+
* backed by a resilient {@link PostgresPool} with automatic reconnection.
|
|
104
|
+
* This is the recommended driver for all use cases.
|
|
105
|
+
*
|
|
106
|
+
* - `'bun-sql'`: Uses Bun's native SQL driver via `drizzle-orm/bun-sql`.
|
|
107
|
+
* May offer slightly better performance but has known parameter binding
|
|
108
|
+
* issues with some libraries (e.g. Better Auth).
|
|
109
|
+
* See: https://github.com/agentuity/sdk/issues/1030
|
|
110
|
+
*
|
|
111
|
+
* @default 'pg'
|
|
112
|
+
*/
|
|
113
|
+
driver?: 'pg' | 'bun-sql';
|
|
92
114
|
}
|
|
93
115
|
|
|
94
116
|
/**
|
|
@@ -113,3 +135,24 @@ export interface PostgresDrizzle<TSchema extends Record<string, unknown> = Recor
|
|
|
113
135
|
*/
|
|
114
136
|
close: () => Promise<void>;
|
|
115
137
|
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The result of creating a PostgreSQL Drizzle instance with the 'pg' driver.
|
|
141
|
+
*
|
|
142
|
+
* @template TSchema - The Drizzle schema type
|
|
143
|
+
*/
|
|
144
|
+
export interface PostgresDrizzlePg<
|
|
145
|
+
TSchema extends Record<string, unknown> = Record<string, never>,
|
|
146
|
+
> {
|
|
147
|
+
/** The Drizzle database instance (node-postgres backed). */
|
|
148
|
+
db: NodePgDatabase<TSchema>;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The underlying resilient PostgreSQL pool with reconnection support.
|
|
152
|
+
* Can be used for raw queries or accessing connection state.
|
|
153
|
+
*/
|
|
154
|
+
client: PostgresPool;
|
|
155
|
+
|
|
156
|
+
/** Closes the underlying pool and releases resources. */
|
|
157
|
+
close: () => Promise<void>;
|
|
158
|
+
}
|