@dotdo/postgres 0.1.2 → 0.1.3
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 +73 -1
- package/dist/client/index.d.ts +47 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +47 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/postgres-client.d.ts +273 -0
- package/dist/client/postgres-client.d.ts.map +1 -0
- package/dist/client/postgres-client.js +389 -0
- package/dist/client/postgres-client.js.map +1 -0
- package/dist/client/types.d.ts +167 -0
- package/dist/client/types.d.ts.map +1 -0
- package/dist/client/types.js +7 -0
- package/dist/client/types.js.map +1 -0
- package/dist/do/index.d.ts +18 -0
- package/dist/do/index.d.ts.map +1 -0
- package/dist/do/index.js +18 -0
- package/dist/do/index.js.map +1 -0
- package/dist/do/postgres.d.ts +110 -0
- package/dist/do/postgres.d.ts.map +1 -0
- package/dist/do/postgres.js +266 -0
- package/dist/do/postgres.js.map +1 -0
- package/dist/do/sql.d.ts +92 -0
- package/dist/do/sql.d.ts.map +1 -0
- package/dist/do/sql.js +204 -0
- package/dist/do/sql.js.map +1 -0
- package/dist/index.d.ts +25 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -30
- package/dist/index.js.map +1 -1
- package/dist/mcp/binding.d.ts +47 -0
- package/dist/mcp/binding.d.ts.map +1 -0
- package/dist/mcp/binding.js +183 -0
- package/dist/mcp/binding.js.map +1 -0
- package/dist/mcp/index.d.ts +92 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +91 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +62 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +278 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools.d.ts +58 -0
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/mcp/tools.js +356 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.d.ts.map +1 -0
- package/dist/mcp/types.js +7 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/pglite/workers-pglite.d.ts +13 -4
- package/dist/pglite/workers-pglite.d.ts.map +1 -1
- package/dist/pglite/workers-pglite.js +110 -5
- package/dist/pglite/workers-pglite.js.map +1 -1
- package/dist/pglite-assets/pglite.data +0 -0
- package/dist/pglite-assets/pglite.wasm +0 -0
- package/dist/worker/background-pglite-manager.d.ts +243 -0
- package/dist/worker/background-pglite-manager.d.ts.map +1 -0
- package/dist/worker/background-pglite-manager.js +528 -0
- package/dist/worker/background-pglite-manager.js.map +1 -0
- package/dist/worker/do-pglite-manager.d.ts +77 -0
- package/dist/worker/do-pglite-manager.d.ts.map +1 -1
- package/dist/worker/do-pglite-manager.js +189 -12
- package/dist/worker/do-pglite-manager.js.map +1 -1
- package/dist/worker/index.d.ts +7 -1
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +19 -1
- package/dist/worker/index.js.map +1 -1
- package/dist/worker/lazy-pglite-manager.d.ts +242 -0
- package/dist/worker/lazy-pglite-manager.d.ts.map +1 -0
- package/dist/worker/lazy-pglite-manager.js +463 -0
- package/dist/worker/lazy-pglite-manager.js.map +1 -0
- package/package.json +16 -3
- package/src/client/index.ts +61 -0
- package/src/client/postgres-client.ts +442 -0
- package/src/client/types.ts +211 -0
- package/src/do/index.ts +18 -0
- package/src/do/postgres.ts +367 -0
- package/src/do/sql.ts +280 -0
- package/src/index.ts +50 -30
- package/src/mcp/binding.ts +236 -0
- package/src/mcp/index.ts +122 -0
- package/src/mcp/server.ts +361 -0
- package/src/mcp/tools.ts +464 -0
- package/src/mcp/types.ts +148 -0
- package/src/pglite/workers-pglite.ts +141 -12
- package/src/pglite-assets/pglite.data +0 -0
- package/src/pglite-assets/pglite.wasm +0 -0
- package/src/worker/background-pglite-manager.ts +680 -0
- package/src/worker/do-pglite-manager.ts +235 -19
- package/src/worker/index.ts +71 -1
- package/src/worker/lazy-pglite-manager.ts +595 -0
- package/dist/iceberg/duckdb-wasm.d.ts +0 -447
- package/dist/iceberg/duckdb-wasm.d.ts.map +0 -1
- package/dist/iceberg/duckdb-wasm.js +0 -600
- package/dist/iceberg/duckdb-wasm.js.map +0 -1
- package/dist/iceberg/test-fixtures.d.ts +0 -151
- package/dist/iceberg/test-fixtures.d.ts.map +0 -1
- package/dist/iceberg/test-fixtures.js +0 -446
- package/dist/iceberg/test-fixtures.js.map +0 -1
- package/dist/worker/__mocks__/cloudflare-workers.d.ts +0 -31
- package/dist/worker/__mocks__/cloudflare-workers.d.ts.map +0 -1
- package/dist/worker/__mocks__/cloudflare-workers.js +0 -33
- package/dist/worker/__mocks__/cloudflare-workers.js.map +0 -1
package/README.md
CHANGED
|
@@ -99,10 +99,22 @@ Done. PostgreSQL at the edge.
|
|
|
99
99
|
| **Latency** | <10ms (edge) | 50-200ms (regional) |
|
|
100
100
|
| **Idle cost** | $0 (hibernation) | $$$ (always running) |
|
|
101
101
|
| **Cache reads** | FREE | Per-query cost |
|
|
102
|
-
| **
|
|
102
|
+
| **Warm starts** | **16ms** (WASM hoisting) | 50-200ms |
|
|
103
|
+
| **Cold starts** | ~1200ms (full WASM) | 50-200ms |
|
|
103
104
|
| **Per-user DBs** | Built-in | Complex infra |
|
|
104
105
|
| **WebSocket** | 95% cheaper | Full connection cost |
|
|
105
106
|
|
|
107
|
+
### Performance
|
|
108
|
+
|
|
109
|
+
| Scenario | Latency | Notes |
|
|
110
|
+
|----------|---------|-------|
|
|
111
|
+
| **Warm query** | 13-16ms | WASM hoisted, consistent |
|
|
112
|
+
| **Warm start** (DO reinstantiated) | **16ms** | 75x faster with WASM hoisting |
|
|
113
|
+
| **Cold start** | ~1200ms | Full WASM initialization |
|
|
114
|
+
| **Non-query endpoints** | **Instant** | Respond while WASM loads |
|
|
115
|
+
|
|
116
|
+
The key insight: **Isolates stay warm much longer than DO class instances**. WASM hoisting at the module level means most requests hit a warm isolate where WASM is already loaded, reducing latency from ~1200ms to ~16ms.
|
|
117
|
+
|
|
106
118
|
## API Reference
|
|
107
119
|
|
|
108
120
|
### Worker Module
|
|
@@ -130,6 +142,19 @@ export const AuthenticatedPostgresDO = createAuthenticatedPostgresDO({
|
|
|
130
142
|
oauthDoBinding: 'OAUTH_DO',
|
|
131
143
|
requiredScopes: ['read', 'write'],
|
|
132
144
|
})
|
|
145
|
+
|
|
146
|
+
// WASM hoisting utilities for diagnostics
|
|
147
|
+
import {
|
|
148
|
+
hasBgHoistedPglite, // Check if WASM is loaded
|
|
149
|
+
isBgWasmLoading, // Check if WASM is loading
|
|
150
|
+
getBgHoistedPgliteDiagnostics, // Get detailed diagnostics
|
|
151
|
+
} from '@dotdo/postgres/worker'
|
|
152
|
+
|
|
153
|
+
// Check WASM state
|
|
154
|
+
console.log('WASM loaded:', hasBgHoistedPglite())
|
|
155
|
+
console.log('WASM loading:', isBgWasmLoading())
|
|
156
|
+
console.log('Diagnostics:', getBgHoistedPgliteDiagnostics())
|
|
157
|
+
// { hasInstance: true, isLoading: false, loadDurationMs: 1156, ... }
|
|
133
158
|
```
|
|
134
159
|
|
|
135
160
|
#### createRoutes
|
|
@@ -155,6 +180,53 @@ app.route('/api/sql', createRoutes(postgresDO))
|
|
|
155
180
|
// GET /schema - Get schema version info
|
|
156
181
|
```
|
|
157
182
|
|
|
183
|
+
#### BackgroundPGLiteManager
|
|
184
|
+
|
|
185
|
+
Eager-but-non-blocking WASM loading for optimal performance.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { BackgroundPGLiteManager, createBackgroundPGLiteManager } from '@dotdo/postgres/worker'
|
|
189
|
+
|
|
190
|
+
// In your Durable Object
|
|
191
|
+
export class PostgresDO extends DurableObject {
|
|
192
|
+
private manager: BackgroundPGLiteManager
|
|
193
|
+
|
|
194
|
+
constructor(ctx: DurableObjectState, env: Env) {
|
|
195
|
+
super(ctx, env)
|
|
196
|
+
this.manager = createBackgroundPGLiteManager({
|
|
197
|
+
database: 'mydb',
|
|
198
|
+
waitUntil: (p) => ctx.waitUntil(p), // Keep DO alive during WASM load
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
async init() {
|
|
203
|
+
// Starts WASM loading in background, returns IMMEDIATELY
|
|
204
|
+
await this.manager.initialize()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Health check - responds INSTANTLY (doesn't wait for WASM)
|
|
208
|
+
ping() {
|
|
209
|
+
return {
|
|
210
|
+
ok: true,
|
|
211
|
+
wasmLoaded: this.manager.isWASMLoaded(),
|
|
212
|
+
wasmLoading: this.manager.isLoading(),
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Query - waits for WASM if not ready (loading already started)
|
|
217
|
+
async query(sql: string) {
|
|
218
|
+
return this.manager.query(sql)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
**Why eager-but-non-blocking?**
|
|
224
|
+
- Pure lazy loading "kicks the can down the road" - first query still pays full ~1200ms
|
|
225
|
+
- Background loading gives the best of both worlds:
|
|
226
|
+
- Non-query endpoints respond instantly
|
|
227
|
+
- WASM starts loading immediately
|
|
228
|
+
- First query only waits for remaining load time (often near-zero)
|
|
229
|
+
|
|
158
230
|
#### WebSocket Handler
|
|
159
231
|
|
|
160
232
|
Real-time query execution and CDC subscriptions via WebSocket.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgresDO WebSocket Client
|
|
3
|
+
*
|
|
4
|
+
* A typed WebSocket client for PostgresDO with rpc.do integration.
|
|
5
|
+
* Provides automatic reconnection, heartbeat, and first-message authentication.
|
|
6
|
+
*
|
|
7
|
+
* @module client
|
|
8
|
+
*
|
|
9
|
+
* @example Basic usage
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
12
|
+
*
|
|
13
|
+
* const client = createPostgresClient({
|
|
14
|
+
* url: 'wss://postgres.example.com/ws',
|
|
15
|
+
* auth: 'your-api-key',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Execute queries
|
|
19
|
+
* const users = await client.query('SELECT * FROM users')
|
|
20
|
+
* const user = await client.queryOne('SELECT * FROM users WHERE id = $1', [1])
|
|
21
|
+
* const count = await client.queryScalar<number>('SELECT COUNT(*) FROM users')
|
|
22
|
+
*
|
|
23
|
+
* // Transactions
|
|
24
|
+
* const tx = await client.transaction()
|
|
25
|
+
* await tx.execute('INSERT INTO users (name) VALUES ($1)', ['Alice'])
|
|
26
|
+
* await tx.commit()
|
|
27
|
+
*
|
|
28
|
+
* // Clean up
|
|
29
|
+
* await client.close()
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example With oauth.do authentication
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
35
|
+
* import { oauthProvider } from 'rpc.do/auth'
|
|
36
|
+
*
|
|
37
|
+
* const client = createPostgresClient({
|
|
38
|
+
* url: 'wss://postgres.example.com/ws',
|
|
39
|
+
* auth: oauthProvider(),
|
|
40
|
+
* onConnect: () => console.log('Connected!'),
|
|
41
|
+
* onReconnecting: (attempt) => console.log(`Reconnecting (${attempt})...`),
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export { PostgresClient, createPostgresClient } from './postgres-client';
|
|
46
|
+
export type { PostgresClientConfig, PostgresDORpcApi, RpcQueryResult, RpcBatchQuery, RpcBatchResult, RpcTransactionOptions, TransactionApi, ColumnInfo, DatabaseStats, ConnectionState, } from './types';
|
|
47
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAGxE,YAAY,EACV,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgresDO WebSocket Client
|
|
3
|
+
*
|
|
4
|
+
* A typed WebSocket client for PostgresDO with rpc.do integration.
|
|
5
|
+
* Provides automatic reconnection, heartbeat, and first-message authentication.
|
|
6
|
+
*
|
|
7
|
+
* @module client
|
|
8
|
+
*
|
|
9
|
+
* @example Basic usage
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
12
|
+
*
|
|
13
|
+
* const client = createPostgresClient({
|
|
14
|
+
* url: 'wss://postgres.example.com/ws',
|
|
15
|
+
* auth: 'your-api-key',
|
|
16
|
+
* })
|
|
17
|
+
*
|
|
18
|
+
* // Execute queries
|
|
19
|
+
* const users = await client.query('SELECT * FROM users')
|
|
20
|
+
* const user = await client.queryOne('SELECT * FROM users WHERE id = $1', [1])
|
|
21
|
+
* const count = await client.queryScalar<number>('SELECT COUNT(*) FROM users')
|
|
22
|
+
*
|
|
23
|
+
* // Transactions
|
|
24
|
+
* const tx = await client.transaction()
|
|
25
|
+
* await tx.execute('INSERT INTO users (name) VALUES ($1)', ['Alice'])
|
|
26
|
+
* await tx.commit()
|
|
27
|
+
*
|
|
28
|
+
* // Clean up
|
|
29
|
+
* await client.close()
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @example With oauth.do authentication
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
35
|
+
* import { oauthProvider } from 'rpc.do/auth'
|
|
36
|
+
*
|
|
37
|
+
* const client = createPostgresClient({
|
|
38
|
+
* url: 'wss://postgres.example.com/ws',
|
|
39
|
+
* auth: oauthProvider(),
|
|
40
|
+
* onConnect: () => console.log('Connected!'),
|
|
41
|
+
* onReconnecting: (attempt) => console.log(`Reconnecting (${attempt})...`),
|
|
42
|
+
* })
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
// Main client export
|
|
46
|
+
export { PostgresClient, createPostgresClient } from './postgres-client';
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,qBAAqB;AACrB,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PostgresClient - WebSocket client for PostgresDO with rpc.do integration
|
|
3
|
+
*
|
|
4
|
+
* Provides typed access to PostgresDO's RPC methods over WebSocket with:
|
|
5
|
+
* - Automatic reconnection with exponential backoff
|
|
6
|
+
* - Heartbeat ping/pong for connection health
|
|
7
|
+
* - First-message authentication
|
|
8
|
+
* - Full TypeScript support
|
|
9
|
+
*
|
|
10
|
+
* @module client/postgres-client
|
|
11
|
+
*
|
|
12
|
+
* @example Basic usage
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
15
|
+
*
|
|
16
|
+
* const client = createPostgresClient({
|
|
17
|
+
* url: 'wss://postgres.example.com/ws',
|
|
18
|
+
* auth: 'your-api-key',
|
|
19
|
+
* })
|
|
20
|
+
*
|
|
21
|
+
* // Execute queries
|
|
22
|
+
* const users = await client.query('SELECT * FROM users')
|
|
23
|
+
* console.log(users.rows)
|
|
24
|
+
*
|
|
25
|
+
* // Single row
|
|
26
|
+
* const user = await client.queryOne('SELECT * FROM users WHERE id = $1', [1])
|
|
27
|
+
*
|
|
28
|
+
* // Scalar value
|
|
29
|
+
* const count = await client.queryScalar<number>('SELECT COUNT(*) FROM users')
|
|
30
|
+
*
|
|
31
|
+
* // Clean up
|
|
32
|
+
* await client.close()
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @example With rpc.do transport
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
38
|
+
* import { capnweb } from 'rpc.do/transports'
|
|
39
|
+
*
|
|
40
|
+
* // Using capnweb transport with reconnection
|
|
41
|
+
* const client = createPostgresClient({
|
|
42
|
+
* url: 'wss://postgres.example.com/ws',
|
|
43
|
+
* auth: () => localStorage.getItem('token'),
|
|
44
|
+
* autoReconnect: true,
|
|
45
|
+
* onConnect: () => console.log('Connected!'),
|
|
46
|
+
* onReconnecting: (attempt) => console.log(`Reconnecting... (${attempt})`),
|
|
47
|
+
* })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
import type { PostgresClientConfig, RpcQueryResult, RpcBatchQuery, RpcBatchResult, RpcTransactionOptions, TransactionApi, ColumnInfo, DatabaseStats, ConnectionState } from './types';
|
|
51
|
+
import type { QueryResultRow } from '../worker/types';
|
|
52
|
+
/**
|
|
53
|
+
* PostgresClient - typed WebSocket client for PostgresDO
|
|
54
|
+
*
|
|
55
|
+
* Uses rpc.do's capnweb transport for efficient RPC communication
|
|
56
|
+
* with automatic reconnection and hibernation support.
|
|
57
|
+
*/
|
|
58
|
+
export declare class PostgresClient {
|
|
59
|
+
private config;
|
|
60
|
+
private rpcClient;
|
|
61
|
+
private transport;
|
|
62
|
+
private connectionPromise;
|
|
63
|
+
private state;
|
|
64
|
+
constructor(config: PostgresClientConfig);
|
|
65
|
+
/**
|
|
66
|
+
* Connect to the PostgresDO WebSocket endpoint
|
|
67
|
+
*/
|
|
68
|
+
private connect;
|
|
69
|
+
/**
|
|
70
|
+
* Establish the WebSocket connection using rpc.do
|
|
71
|
+
*/
|
|
72
|
+
private establishConnection;
|
|
73
|
+
/**
|
|
74
|
+
* Ensure we're connected before making RPC calls
|
|
75
|
+
*/
|
|
76
|
+
private ensureConnected;
|
|
77
|
+
/**
|
|
78
|
+
* Execute a SQL query and return full results
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const result = await client.query('SELECT * FROM users WHERE active = $1', [true])
|
|
83
|
+
* console.log(result.rows)
|
|
84
|
+
* console.log(`${result.rowCount} rows returned in ${result.durationMs}ms`)
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
query<T extends QueryResultRow = QueryResultRow>(sql: string, params?: unknown[]): Promise<RpcQueryResult<T>>;
|
|
88
|
+
/**
|
|
89
|
+
* Execute a query and return only the first row
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const user = await client.queryOne('SELECT * FROM users WHERE id = $1', [1])
|
|
94
|
+
* if (user) {
|
|
95
|
+
* console.log(user.name)
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
queryOne<T extends QueryResultRow = QueryResultRow>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
100
|
+
/**
|
|
101
|
+
* Execute a query and return a scalar value (first column of first row)
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const count = await client.queryScalar<number>('SELECT COUNT(*) FROM users')
|
|
106
|
+
* console.log(`Total users: ${count}`)
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
queryScalar<T = unknown>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
110
|
+
/**
|
|
111
|
+
* Execute a statement that doesn't return rows
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const { rowCount } = await client.execute('DELETE FROM users WHERE inactive = true')
|
|
116
|
+
* console.log(`Deleted ${rowCount} inactive users`)
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
120
|
+
rowCount: number;
|
|
121
|
+
durationMs: number;
|
|
122
|
+
}>;
|
|
123
|
+
/**
|
|
124
|
+
* Execute multiple queries in a single round trip
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```typescript
|
|
128
|
+
* const result = await client.batch([
|
|
129
|
+
* { sql: 'SELECT * FROM users' },
|
|
130
|
+
* { sql: 'SELECT * FROM orders' },
|
|
131
|
+
* { sql: 'SELECT * FROM products' },
|
|
132
|
+
* ])
|
|
133
|
+
* const [users, orders, products] = result.results
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
batch(queries: RpcBatchQuery[]): Promise<RpcBatchResult>;
|
|
137
|
+
/**
|
|
138
|
+
* Execute multiple queries within a transaction
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const result = await client.batchTransaction([
|
|
143
|
+
* { sql: 'INSERT INTO users (name) VALUES ($1)', params: ['Alice'] },
|
|
144
|
+
* { sql: 'INSERT INTO audit_log (action) VALUES ($1)', params: ['user_created'] },
|
|
145
|
+
* ])
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
batchTransaction(queries: RpcBatchQuery[]): Promise<RpcBatchResult>;
|
|
149
|
+
/**
|
|
150
|
+
* Start a transaction and return a transaction API
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const tx = await client.transaction()
|
|
155
|
+
* try {
|
|
156
|
+
* await tx.execute('INSERT INTO users (name) VALUES ($1)', ['Alice'])
|
|
157
|
+
* await tx.execute('INSERT INTO audit_log (action) VALUES ($1)', ['user_created'])
|
|
158
|
+
* await tx.commit()
|
|
159
|
+
* } catch (error) {
|
|
160
|
+
* await tx.rollback()
|
|
161
|
+
* throw error
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*
|
|
165
|
+
* @example With isolation level
|
|
166
|
+
* ```typescript
|
|
167
|
+
* const tx = await client.transaction({ isolationLevel: 'SERIALIZABLE' })
|
|
168
|
+
* // ... perform queries
|
|
169
|
+
* await tx.commit()
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
transaction(options?: RpcTransactionOptions): Promise<TransactionApi>;
|
|
173
|
+
/**
|
|
174
|
+
* Health check - verify the database is responsive
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* const { ok, durationMs } = await client.ping()
|
|
179
|
+
* console.log(`Database responded in ${durationMs}ms`)
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
ping(): Promise<{
|
|
183
|
+
ok: true;
|
|
184
|
+
durationMs: number;
|
|
185
|
+
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Get the PostgreSQL version
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const version = await client.version()
|
|
192
|
+
* console.log(`PostgreSQL version: ${version}`)
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
version(): Promise<string>;
|
|
196
|
+
/**
|
|
197
|
+
* List all tables in the public schema
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const tables = await client.listTables()
|
|
202
|
+
* console.log('Tables:', tables)
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
listTables(): Promise<string[]>;
|
|
206
|
+
/**
|
|
207
|
+
* Get schema information for a table
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* const columns = await client.describeTable('users')
|
|
212
|
+
* for (const col of columns) {
|
|
213
|
+
* console.log(`${col.column_name}: ${col.data_type}`)
|
|
214
|
+
* }
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
describeTable(tableName: string): Promise<ColumnInfo[]>;
|
|
218
|
+
/**
|
|
219
|
+
* Get database statistics
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* const stats = await client.getStats()
|
|
224
|
+
* console.log(`Queries: ${stats.queryCount}, Avg: ${stats.avgDurationMs}ms`)
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
getStats(): Promise<DatabaseStats>;
|
|
228
|
+
/**
|
|
229
|
+
* Get current connection state
|
|
230
|
+
*/
|
|
231
|
+
getConnectionState(): ConnectionState;
|
|
232
|
+
/**
|
|
233
|
+
* Check if currently connected
|
|
234
|
+
*/
|
|
235
|
+
isConnected(): boolean;
|
|
236
|
+
/**
|
|
237
|
+
* Close the connection
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```typescript
|
|
241
|
+
* await client.close()
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
close(): Promise<void>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create a PostgresClient instance
|
|
248
|
+
*
|
|
249
|
+
* @example Basic usage
|
|
250
|
+
* ```typescript
|
|
251
|
+
* import { createPostgresClient } from '@dotdo/postgres/client'
|
|
252
|
+
*
|
|
253
|
+
* const client = createPostgresClient({
|
|
254
|
+
* url: 'wss://postgres.example.com/ws',
|
|
255
|
+
* auth: 'your-api-key',
|
|
256
|
+
* })
|
|
257
|
+
*
|
|
258
|
+
* const users = await client.query('SELECT * FROM users')
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* @example With reconnection callbacks
|
|
262
|
+
* ```typescript
|
|
263
|
+
* const client = createPostgresClient({
|
|
264
|
+
* url: 'wss://postgres.example.com/ws',
|
|
265
|
+
* auth: () => getAuthToken(),
|
|
266
|
+
* onConnect: () => console.log('Connected!'),
|
|
267
|
+
* onDisconnect: (reason) => console.log('Disconnected:', reason),
|
|
268
|
+
* onReconnecting: (attempt) => console.log(`Reconnecting (${attempt})...`),
|
|
269
|
+
* })
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export declare function createPostgresClient(config: PostgresClientConfig): PostgresClient;
|
|
273
|
+
//# sourceMappingURL=postgres-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"postgres-client.d.ts","sourceRoot":"","sources":["../../src/client/postgres-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,KAAK,EACV,oBAAoB,EAEpB,cAAc,EACd,aAAa,EACb,cAAc,EACd,qBAAqB,EACrB,cAAc,EACd,UAAU,EACV,aAAa,EACb,eAAe,EAChB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAErD;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,SAAS,CAAgC;IACjD,OAAO,CAAC,SAAS,CAAqC;IACtD,OAAO,CAAC,iBAAiB,CAA6B;IACtD,OAAO,CAAC,KAAK,CAAkC;gBAEnC,MAAM,EAAE,oBAAoB;IAaxC;;OAEG;YACW,OAAO;IAoBrB;;OAEG;YACW,mBAAmB;IA+BjC;;OAEG;YACW,eAAe;IAgB7B;;;;;;;;;OASG;IACG,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,EACnD,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;IAK7B;;;;;;;;;;OAUG;IACG,QAAQ,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,EACtD,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKpB;;;;;;;;OAQG;IACG,WAAW,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKlF;;;;;;;;OAQG;IACG,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IASjG;;;;;;;;;;;;OAYG;IACG,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAK9D;;;;;;;;;;OAUG;IACG,gBAAgB,CAAC,OAAO,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IASzE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,WAAW,CAAC,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,cAAc,CAAC;IAS3E;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC;QAAE,EAAE,EAAE,IAAI,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAKvD;;;;;;;;OAQG;IACG,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;IAKhC;;;;;;;;OAQG;IACG,UAAU,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAKrC;;;;;;;;;;OAUG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAK7D;;;;;;;;OAQG;IACG,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC;IASxC;;OAEG;IACH,kBAAkB,IAAI,eAAe;IAIrC;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;;;;;;OAOG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CAEjF"}
|