@prairielearn/postgres 1.2.0 → 1.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @prairielearn/postgres
2
2
 
3
+ ## 1.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ce16bede7: Add `queryCursor` and `queryValidatedCursor` functions
8
+
9
+ ## 1.3.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 5ae096ba7: Add `totalCount`, `idleCount`, and `waitingCount` properties to `PostgresPool`
14
+
3
15
  ## 1.1.0
4
16
 
5
17
  ### Minor Changes
package/README.md CHANGED
@@ -156,6 +156,41 @@ const { user, course } = await sqldb.runInTransactionAsync(async () => {
156
156
 
157
157
  `runInTransaction` will start a transaction and then execute the provided function. Any nested query will use the same client and thus run inside the transaction. If the function throws an error, the transaction is rolled back; otherwise, it is committed.
158
158
 
159
+ ### Cursors
160
+
161
+ For very large queries that don't need to fit in memory all at once, it's possible to use a cursor to read a limited number of rows at a time.
162
+
163
+ ```ts
164
+ import { queryCursor } from '@prairielearn/postgres';
165
+
166
+ const cursor = await queryCursor(sql.select_all_users, {});
167
+ for await (const users of cursor.iterate(100)) {
168
+ // `users` will have up to 100 rows in it.
169
+ for (const user of users) {
170
+ console.log(user);
171
+ }
172
+ }
173
+ ```
174
+
175
+ You can optionally pass a Zod schema to parse and validate each row:
176
+
177
+ ```ts
178
+ import { z } from 'zod';
179
+ import { queryValidatedCursor } from '@prairielearn/postgres';
180
+
181
+ const UserSchema = z.object({
182
+ id: z.string(),
183
+ name: z.string(),
184
+ });
185
+
186
+ const cursor = await queryValidatedCursor(sql.select_all_users, {}, UserSchema);
187
+ for await (const users of cursor.iterate(100)) {
188
+ for (const user of users) {
189
+ console.log(user);
190
+ }
191
+ }
192
+ ```
193
+
159
194
  ### Callback-style functions
160
195
 
161
196
  For most functions that return promises, there are corresponding versions that work with Node-style callbacks:
@@ -1,28 +1,31 @@
1
1
  /// <reference types="node" />
2
+ import { PostgresPool } from './pool';
3
+ declare const defaultPool: PostgresPool;
4
+ export { defaultPool };
2
5
  export declare const init: (arg1: import("pg").PoolConfig, arg2: (error: Error, client: import("pg").PoolClient) => void, callback: (err: NodeJS.ErrnoException) => void) => void;
3
6
  export declare const initAsync: (pgConfig: import("pg").PoolConfig, idleErrorHandler: (error: Error, client: import("pg").PoolClient) => void) => Promise<void>;
4
7
  export declare const close: (callback: (err: NodeJS.ErrnoException) => void) => void;
5
8
  export declare const closeAsync: () => Promise<void>;
6
9
  export declare const getClientAsync: () => Promise<import("pg").PoolClient>;
7
10
  export declare const getClient: (callback: (error: Error | null, client?: import("pg").PoolClient | undefined, done?: (() => void) | undefined) => void) => void;
8
- export declare const queryWithClient: (arg1: import("pg").PoolClient, arg2: string, arg3: any[] | Record<string, any>, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
9
- export declare const queryWithClientAsync: (client: import("pg").PoolClient, sql: string, params: any[] | Record<string, any>) => Promise<import("pg").QueryResult<any>>;
10
- export declare const queryWithClientOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[] | Record<string, any>, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
11
- export declare const queryWithClientOneRowAsync: (client: import("pg").PoolClient, sql: string, params: any[] | Record<string, any>) => Promise<import("pg").QueryResult<any>>;
12
- export declare const queryWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[] | Record<string, any>, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
13
- export declare const queryWithClientZeroOrOneRowAsync: (client: import("pg").PoolClient, sql: string, params: any[] | Record<string, any>) => Promise<import("pg").QueryResult<any>>;
11
+ export declare const queryWithClient: (arg1: import("pg").PoolClient, arg2: string, arg3: import("./pool").QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
12
+ export declare const queryWithClientAsync: (client: import("pg").PoolClient, sql: string, params: import("./pool").QueryParams) => Promise<import("pg").QueryResult<any>>;
13
+ export declare const queryWithClientOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: import("./pool").QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
14
+ export declare const queryWithClientOneRowAsync: (client: import("pg").PoolClient, sql: string, params: import("./pool").QueryParams) => Promise<import("pg").QueryResult<any>>;
15
+ export declare const queryWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: import("./pool").QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
16
+ export declare const queryWithClientZeroOrOneRowAsync: (client: import("pg").PoolClient, sql: string, params: import("./pool").QueryParams) => Promise<import("pg").QueryResult<any>>;
14
17
  export declare const rollbackWithClientAsync: (client: import("pg").PoolClient) => Promise<void>;
15
18
  export declare const rollbackWithClient: (client: import("pg").PoolClient, _done: (release?: any) => void, callback: (err: Error | null) => void) => void;
16
19
  export declare const beginTransactionAsync: () => Promise<import("pg").PoolClient>;
17
20
  export declare const endTransactionAsync: (client: import("pg").PoolClient, err: Error | null | undefined) => Promise<void>;
18
21
  export declare const endTransaction: (client: import("pg").PoolClient, _done: (rollback?: any) => void, err: Error | null | undefined, callback: (error: Error | null) => void) => void;
19
22
  export declare const runInTransactionAsync: <T>(fn: (client: import("pg").PoolClient) => Promise<T>) => Promise<T>;
20
- export declare const query: (arg1: string, arg2: any[] | Record<string, any>, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
21
- export declare const queryAsync: (sql: string, params: any[] | Record<string, any>) => Promise<import("pg").QueryResult<any>>;
22
- export declare const queryOneRow: (arg1: string, arg2: any[] | Record<string, any>, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
23
- export declare const queryOneRowAsync: (sql: string, params: any[] | Record<string, any>) => Promise<import("pg").QueryResult<any>>;
24
- export declare const queryZeroOrOneRow: (arg1: string, arg2: any[] | Record<string, any>, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
25
- export declare const queryZeroOrOneRowAsync: (sql: string, params: any[] | Record<string, any>) => Promise<import("pg").QueryResult<any>>;
23
+ export declare const query: (arg1: string, arg2: import("./pool").QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
24
+ export declare const queryAsync: (sql: string, params: import("./pool").QueryParams) => Promise<import("pg").QueryResult<any>>;
25
+ export declare const queryOneRow: (arg1: string, arg2: import("./pool").QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
26
+ export declare const queryOneRowAsync: (sql: string, params: import("./pool").QueryParams) => Promise<import("pg").QueryResult<any>>;
27
+ export declare const queryZeroOrOneRow: (arg1: string, arg2: import("./pool").QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
28
+ export declare const queryZeroOrOneRowAsync: (sql: string, params: import("./pool").QueryParams) => Promise<import("pg").QueryResult<any>>;
26
29
  export declare const call: (arg1: string, arg2: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
27
30
  export declare const callAsync: (functionName: string, params: any[]) => Promise<import("pg").QueryResult<any>>;
28
31
  export declare const callOneRow: (arg1: string, arg2: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
@@ -35,15 +38,18 @@ export declare const callWithClientOneRow: (arg1: import("pg").PoolClient, arg2:
35
38
  export declare const callWithClientOneRowAsync: (client: import("pg").PoolClient, functionName: string, params: any[]) => Promise<import("pg").QueryResult<any>>;
36
39
  export declare const callWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
37
40
  export declare const callWithClientZeroOrOneRowAsync: (client: import("pg").PoolClient, functionName: string, params: any[]) => Promise<import("pg").QueryResult<any>>;
38
- export declare const queryValidatedRows: <Model extends import("zod").ZodTypeAny>(query: string, params: Record<string, any>, model: Model) => Promise<import("zod").TypeOf<Model>[]>;
39
- export declare const queryValidatedOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: Record<string, any>, model: Model) => Promise<import("zod").TypeOf<Model>>;
40
- export declare const queryValidatedZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: Record<string, any>, model: Model) => Promise<import("zod").TypeOf<Model> | null>;
41
- export declare const queryValidatedSingleColumnRows: <Model extends import("zod").ZodTypeAny>(query: string, params: Record<string, any>, model: Model) => Promise<import("zod").TypeOf<Model>[]>;
42
- export declare const queryValidatedSingleColumnOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: Record<string, any>, model: Model) => Promise<import("zod").TypeOf<Model>>;
43
- export declare const queryValidatedSingleColumnZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: Record<string, any>, model: Model) => Promise<import("zod").TypeOf<Model> | null>;
41
+ export declare const queryValidatedRows: <Model extends import("zod").ZodTypeAny>(query: string, params: import("./pool").QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>[]>;
42
+ export declare const queryValidatedOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: import("./pool").QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>>;
43
+ export declare const queryValidatedZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: import("./pool").QueryParams, model: Model) => Promise<import("zod").TypeOf<Model> | null>;
44
+ export declare const queryValidatedSingleColumnRows: <Model extends import("zod").ZodTypeAny>(query: string, params: import("./pool").QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>[]>;
45
+ export declare const queryValidatedSingleColumnOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: import("./pool").QueryParams, model: Model) => Promise<import("zod").TypeOf<Model>>;
46
+ export declare const queryValidatedSingleColumnZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(query: string, params: import("./pool").QueryParams, model: Model) => Promise<import("zod").TypeOf<Model> | null>;
44
47
  export declare const callValidatedRows: <Model extends import("zod").ZodTypeAny>(sprocName: string, params: any[], model: Model) => Promise<import("zod").TypeOf<Model>[]>;
45
48
  export declare const callValidatedOneRow: <Model extends import("zod").ZodTypeAny>(sprocName: string, params: any[], model: Model) => Promise<import("zod").TypeOf<Model>>;
46
49
  export declare const callValidatedZeroOrOneRow: <Model extends import("zod").ZodTypeAny>(sprocName: string, params: any[], model: Model) => Promise<import("zod").TypeOf<Model> | null>;
50
+ export declare const queryCursorWithClient: (client: import("pg").PoolClient, sql: string, params: import("./pool").QueryParams) => Promise<import("pg-cursor")<any>>;
51
+ export declare const queryCursor: <Model extends import("zod").ZodTypeAny>(sql: string, params: import("./pool").QueryParams) => Promise<import("./pool").CursorIterator<import("zod").TypeOf<Model>>>;
52
+ export declare const queryValidatedCursor: <Model extends import("zod").ZodTypeAny>(sql: string, params: import("./pool").QueryParams, model: Model) => Promise<import("./pool").CursorIterator<import("zod").TypeOf<Model>>>;
47
53
  export declare const setSearchSchema: (schema: string) => Promise<void>;
48
54
  export declare const getSearchSchema: () => string | null;
49
55
  export declare const setRandomSearchSchema: (arg1: string, callback: (err: NodeJS.ErrnoException, result: string) => void) => void;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setRandomSearchSchemaAsync = exports.setRandomSearchSchema = exports.getSearchSchema = exports.setSearchSchema = exports.callValidatedZeroOrOneRow = exports.callValidatedOneRow = exports.callValidatedRows = exports.queryValidatedSingleColumnZeroOrOneRow = exports.queryValidatedSingleColumnOneRow = exports.queryValidatedSingleColumnRows = exports.queryValidatedZeroOrOneRow = exports.queryValidatedOneRow = exports.queryValidatedRows = exports.callWithClientZeroOrOneRowAsync = exports.callWithClientZeroOrOneRow = exports.callWithClientOneRowAsync = exports.callWithClientOneRow = exports.callWithClientAsync = exports.callWithClient = exports.callZeroOrOneRowAsync = exports.callZeroOrOneRow = exports.callOneRowAsync = exports.callOneRow = exports.callAsync = exports.call = exports.queryZeroOrOneRowAsync = exports.queryZeroOrOneRow = exports.queryOneRowAsync = exports.queryOneRow = exports.queryAsync = exports.query = exports.runInTransactionAsync = exports.endTransaction = exports.endTransactionAsync = exports.beginTransactionAsync = exports.rollbackWithClient = exports.rollbackWithClientAsync = exports.queryWithClientZeroOrOneRowAsync = exports.queryWithClientZeroOrOneRow = exports.queryWithClientOneRowAsync = exports.queryWithClientOneRow = exports.queryWithClientAsync = exports.queryWithClient = exports.getClient = exports.getClientAsync = exports.closeAsync = exports.close = exports.initAsync = exports.init = void 0;
3
+ exports.setSearchSchema = exports.queryValidatedCursor = exports.queryCursor = exports.queryCursorWithClient = exports.callValidatedZeroOrOneRow = exports.callValidatedOneRow = exports.callValidatedRows = exports.queryValidatedSingleColumnZeroOrOneRow = exports.queryValidatedSingleColumnOneRow = exports.queryValidatedSingleColumnRows = exports.queryValidatedZeroOrOneRow = exports.queryValidatedOneRow = exports.queryValidatedRows = exports.callWithClientZeroOrOneRowAsync = exports.callWithClientZeroOrOneRow = exports.callWithClientOneRowAsync = exports.callWithClientOneRow = exports.callWithClientAsync = exports.callWithClient = exports.callZeroOrOneRowAsync = exports.callZeroOrOneRow = exports.callOneRowAsync = exports.callOneRow = exports.callAsync = exports.call = exports.queryZeroOrOneRowAsync = exports.queryZeroOrOneRow = exports.queryOneRowAsync = exports.queryOneRow = exports.queryAsync = exports.query = exports.runInTransactionAsync = exports.endTransaction = exports.endTransactionAsync = exports.beginTransactionAsync = exports.rollbackWithClient = exports.rollbackWithClientAsync = exports.queryWithClientZeroOrOneRowAsync = exports.queryWithClientZeroOrOneRow = exports.queryWithClientOneRowAsync = exports.queryWithClientOneRow = exports.queryWithClientAsync = exports.queryWithClient = exports.getClient = exports.getClientAsync = exports.closeAsync = exports.close = exports.initAsync = exports.init = exports.defaultPool = void 0;
4
+ exports.setRandomSearchSchemaAsync = exports.setRandomSearchSchema = exports.getSearchSchema = void 0;
4
5
  const pool_1 = require("./pool");
5
6
  const defaultPool = new pool_1.PostgresPool();
7
+ exports.defaultPool = defaultPool;
6
8
  // We re-expose all functions from the default pool here to account for the
7
9
  // default case of a shared global pool of clients. If someone want to create
8
10
  // their own pool, we expose the `PostgresPool` class.
@@ -56,6 +58,9 @@ exports.queryValidatedSingleColumnZeroOrOneRow = defaultPool.queryValidatedSingl
56
58
  exports.callValidatedRows = defaultPool.callValidatedRows.bind(defaultPool);
57
59
  exports.callValidatedOneRow = defaultPool.callValidatedOneRow.bind(defaultPool);
58
60
  exports.callValidatedZeroOrOneRow = defaultPool.callValidatedZeroOrOneRow.bind(defaultPool);
61
+ exports.queryCursorWithClient = defaultPool.queryCursorWithClient.bind(defaultPool);
62
+ exports.queryCursor = defaultPool.queryCursor.bind(defaultPool);
63
+ exports.queryValidatedCursor = defaultPool.queryValidatedCursor.bind(defaultPool);
59
64
  exports.setSearchSchema = defaultPool.setSearchSchema.bind(defaultPool);
60
65
  exports.getSearchSchema = defaultPool.getSearchSchema.bind(defaultPool);
61
66
  exports.setRandomSearchSchema = defaultPool.setRandomSearchSchema.bind(defaultPool);
@@ -1 +1 @@
1
- {"version":3,"file":"default-pool.js","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":";;;AAAA,iCAAsC;AAEtC,MAAM,WAAW,GAAG,IAAI,mBAAY,EAAE,CAAC;AAEvC,2EAA2E;AAC3E,6EAA6E;AAC7E,sDAAsD;AACtD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACzD,QAAA,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1C,QAAA,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACpD,QAAA,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;A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AACpD,QAAA,sCAAsC,GACjD,WAAW,CAAC,sCAAsC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1D,QAAA,iBAAiB,GAAG,WAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACpE,QAAA,mBAAmB,GAAG,WAAW,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACxE,QAAA,yBAAyB,GAAG,WAAW,CAAC,yBAAyB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACpF,QAAA,qBAAqB,GAAG,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC5E,QAAA,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACxD,QAAA,oBAAoB,GAAG,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC1E,QAAA,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAChE,QAAA,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAChE,QAAA,qBAAqB,GAAG,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC5E,QAAA,0BAA0B,GAAG,WAAW,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC"}
@@ -27,29 +27,34 @@ const chai_1 = require("chai");
27
27
  const pool_1 = require("./pool");
28
28
  const pgPool = __importStar(require("./default-pool"));
29
29
  /**
30
- * Returns true if the property on `PostgresPool` should be considered
31
- * hidden - that is, if it should be available on the module's exports.
30
+ * Properties on {@link PostgresPool} that should not be available on the default
31
+ * pool's exports.
32
32
  */
33
- function isHiddenProperty(property) {
34
- switch (property) {
35
- case 'pool':
36
- case 'alsClient':
37
- case 'searchSchema':
38
- return true;
39
- default:
40
- return false;
41
- }
42
- }
33
+ const HIDDEN_PROPERTIES = new Set([
34
+ // Private members
35
+ 'pool',
36
+ 'alsClient',
37
+ 'searchSchema',
38
+ '_queryCount',
39
+ 'queryValidatedCursorInternal',
40
+ // Getters
41
+ 'totalCount',
42
+ 'idleCount',
43
+ 'waitingCount',
44
+ 'queryCount',
45
+ ]);
43
46
  describe('sqldb', () => {
44
47
  it('exports the full PostgresPool interface', () => {
45
48
  const pool = new pool_1.PostgresPool();
46
49
  Object.getOwnPropertyNames(pool)
47
- .filter((n) => !isHiddenProperty(n))
50
+ .filter((n) => !HIDDEN_PROPERTIES.has(n))
48
51
  .forEach((prop) => {
49
52
  chai_1.assert.property(pgPool, prop);
50
53
  chai_1.assert.ok(pgPool[prop]);
51
54
  });
52
- Object.getOwnPropertyNames(Object.getPrototypeOf(pool)).forEach((prop) => {
55
+ Object.getOwnPropertyNames(Object.getPrototypeOf(pool))
56
+ .filter((n) => !HIDDEN_PROPERTIES.has(n))
57
+ .forEach((prop) => {
53
58
  chai_1.assert.property(pgPool, prop);
54
59
  chai_1.assert.ok(pgPool[prop]);
55
60
  });
@@ -1 +1 @@
1
- {"version":3,"file":"default-pool.test.js","sourceRoot":"","sources":["../src/default-pool.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA8B;AAC9B,iCAAsC;AACtC,uDAAyC;AAEzC;;;GAGG;AACH,SAAS,gBAAgB,CAAC,QAAgB;IACxC,QAAQ,QAAQ,EAAE;QAChB,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW,CAAC;QACjB,KAAK,cAAc;YACjB,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC;AAED,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,IAAI,GAAG,IAAI,mBAAY,EAAE,CAAC;QAEhC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;aAC7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AAG,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC1D,cAAc;SACf,CAAC;QAEF,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAChD,aAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,mCAAiD;AAAxC,iGAAA,OAAO,OAAA;AAAE,sGAAA,YAAY,OAAA;AAC9B,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AACrB,iDAA+B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,mCAAiD;AAAxC,iGAAA,OAAO,OAAA;AAAE,sGAAA,YAAY,OAAA;AAC9B,+BAAsC;AAA7B,oGAAA,YAAY,OAAA;AAErB,iDAA+B"}
package/dist/pool.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import pg, { QueryResult } from 'pg';
3
+ import Cursor from 'pg-cursor';
3
4
  import { z } from 'zod';
4
- type Params = Record<string, any> | any[];
5
+ export type QueryParams = Record<string, any> | any[];
6
+ export interface CursorIterator<T> {
7
+ iterate: (batchSize: number) => AsyncGenerator<T[]>;
8
+ }
5
9
  export declare class PostgresError extends Error {
6
10
  data: Record<string, any>;
7
11
  constructor(message: string, data: Record<string, any>);
@@ -17,6 +21,8 @@ export declare class PostgresPool {
17
21
  */
18
22
  private alsClient;
19
23
  private searchSchema;
24
+ /** Tracks the total number of queries executed by this pool. */
25
+ private _queryCount;
20
26
  /**
21
27
  * Creates a new connection pool and attempts to connect to the database.
22
28
  */
@@ -50,31 +56,31 @@ export declare class PostgresPool {
50
56
  /**
51
57
  * Performs a query with the given client.
52
58
  */
53
- queryWithClientAsync(client: pg.PoolClient, sql: string, params: Params): Promise<pg.QueryResult>;
59
+ queryWithClientAsync(client: pg.PoolClient, sql: string, params: QueryParams): Promise<pg.QueryResult>;
54
60
  /**
55
61
  * Performs a query with the given client.
56
62
  */
57
- queryWithClient: (arg1: pg.PoolClient, arg2: string, arg3: Params, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
63
+ queryWithClient: (arg1: pg.PoolClient, arg2: string, arg3: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
58
64
  /**
59
65
  * Performs a query with the given client. Errors if the query returns more
60
66
  * than one row.
61
67
  */
62
- queryWithClientOneRowAsync(client: pg.PoolClient, sql: string, params: Params): Promise<pg.QueryResult>;
68
+ queryWithClientOneRowAsync(client: pg.PoolClient, sql: string, params: QueryParams): Promise<pg.QueryResult>;
63
69
  /**
64
70
  * Performs a query with the given client. Errors if the query returns more
65
71
  * than one row.
66
72
  */
67
- queryWithClientOneRow: (arg1: pg.PoolClient, arg2: string, arg3: Params, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
73
+ queryWithClientOneRow: (arg1: pg.PoolClient, arg2: string, arg3: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
68
74
  /**
69
75
  * Performs a query with the given client. Errors if the query returns more
70
76
  * than one row.
71
77
  */
72
- queryWithClientZeroOrOneRowAsync(client: pg.PoolClient, sql: string, params: Params): Promise<QueryResult>;
78
+ queryWithClientZeroOrOneRowAsync(client: pg.PoolClient, sql: string, params: QueryParams): Promise<QueryResult>;
73
79
  /**
74
80
  * Performs a query with the given client. Errors if the query returns more
75
81
  * than one row.
76
82
  */
77
- queryWithClientZeroOrOneRow: (arg1: pg.PoolClient, arg2: string, arg3: Params, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
83
+ queryWithClientZeroOrOneRow: (arg1: pg.PoolClient, arg2: string, arg3: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
78
84
  /**
79
85
  * Rolls back the current transaction for the given client.
80
86
  */
@@ -109,31 +115,31 @@ export declare class PostgresPool {
109
115
  /**
110
116
  * Executes a query with the specified parameters.
111
117
  */
112
- queryAsync(sql: string, params: Params): Promise<QueryResult>;
118
+ queryAsync(sql: string, params: QueryParams): Promise<QueryResult>;
113
119
  /**
114
120
  * Executes a query with the specified parameters.
115
121
  */
116
- query: (arg1: string, arg2: Params, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
122
+ query: (arg1: string, arg2: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
117
123
  /**
118
124
  * Executes a query with the specified parameters. Errors if the query does
119
125
  * not return exactly one row.
120
126
  */
121
- queryOneRowAsync(sql: string, params: Params): Promise<pg.QueryResult>;
127
+ queryOneRowAsync(sql: string, params: QueryParams): Promise<pg.QueryResult>;
122
128
  /**
123
129
  * Executes a query with the specified parameters. Errors if the query does
124
130
  * not return exactly one row.
125
131
  */
126
- queryOneRow: (arg1: string, arg2: Params, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
132
+ queryOneRow: (arg1: string, arg2: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
127
133
  /**
128
134
  * Executes a query with the specified parameters. Errors if the query
129
135
  * returns more than one row.
130
136
  */
131
- queryZeroOrOneRowAsync(sql: string, params: Params): Promise<pg.QueryResult>;
137
+ queryZeroOrOneRowAsync(sql: string, params: QueryParams): Promise<pg.QueryResult>;
132
138
  /**
133
139
  * Executes a query with the specified parameters. Errors if the query
134
140
  * returns more than one row.
135
141
  */
136
- queryZeroOrOneRow: (arg1: string, arg2: Params, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
142
+ queryZeroOrOneRow: (arg1: string, arg2: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
137
143
  /**
138
144
  * Calls the given function with the specified parameters.
139
145
  */
@@ -191,55 +197,70 @@ export declare class PostgresPool {
191
197
  */
192
198
  callWithClientZeroOrOneRow: (arg1: pg.PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: pg.QueryResult<any>) => void) => void;
193
199
  /**
194
- * Wrapper around {@link queryAsync} that validates that the returned data
195
- * matches the given validation model. Returns only the rows of the query.
200
+ * Wrapper around {@link queryAsync} that parses the resulting rows with the
201
+ * given Zod schema. Returns only the rows of the query.
196
202
  */
197
- queryValidatedRows<Model extends z.ZodTypeAny>(query: string, params: Record<string, any>, model: Model): Promise<z.infer<Model>[]>;
203
+ queryValidatedRows<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>[]>;
198
204
  /**
199
- * Wrapper around {@link queryOneRowAsync} that validates that the returned data
200
- * matches the given validation model. Returns only a single row of the query.
205
+ * Wrapper around {@link queryOneRowAsync} that parses the resulting row with
206
+ * the given Zod schema. Returns only a single row of the query.
201
207
  */
202
- queryValidatedOneRow<Model extends z.ZodTypeAny>(query: string, params: Record<string, any>, model: Model): Promise<z.infer<Model>>;
208
+ queryValidatedOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>>;
203
209
  /**
204
- * Wrapper around {@link queryZeroOrOneRowAsync} that validates that the
205
- * returned data matches the given validation model, if it return anything.
206
- * Returns either the single row of the query or `null`.
210
+ * Wrapper around {@link queryZeroOrOneRowAsync} that parses the resulting row
211
+ * (if any) with the given Zod schema. Returns either a single row or `null`.
207
212
  */
208
- queryValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(query: string, params: Record<string, any>, model: Model): Promise<z.infer<Model> | null>;
213
+ queryValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model> | null>;
209
214
  /**
210
215
  * Wrapper around {@link queryAsync} that validates that only one column is
211
- * returned and the data in it matches the given validation model. Returns only
216
+ * returned and parses the data in it with the given Zod schema. Returns only
212
217
  * the single column of the query as an array.
213
218
  */
214
- queryValidatedSingleColumnRows<Model extends z.ZodTypeAny>(query: string, params: Record<string, any>, model: Model): Promise<z.infer<Model>[]>;
219
+ queryValidatedSingleColumnRows<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>[]>;
215
220
  /**
216
221
  * Wrapper around {@link queryOneRowAsync} that validates that only one column
217
- * is returned and the data in it matches the given validation model. Returns
222
+ * is returned and parses the data in it with the given Zod schema. Returns
218
223
  * only the single entry.
219
224
  */
220
- queryValidatedSingleColumnOneRow<Model extends z.ZodTypeAny>(query: string, params: Record<string, any>, model: Model): Promise<z.infer<Model>>;
225
+ queryValidatedSingleColumnOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model>>;
221
226
  /**
222
227
  * Wrapper around {@link queryZeroOrOneRowAsync} that validates that only one
223
- * column is returned and the data in it matches the given validation model, if
224
- * it return anything. Returns either the single row of the query or `null`.
228
+ * column is returned and parses the data in it (if any) with the given Zod
229
+ * schema. Returns either the single row of the query or `null`.
225
230
  */
226
- queryValidatedSingleColumnZeroOrOneRow<Model extends z.ZodTypeAny>(query: string, params: Record<string, any>, model: Model): Promise<z.infer<Model> | null>;
231
+ queryValidatedSingleColumnZeroOrOneRow<Model extends z.ZodTypeAny>(query: string, params: QueryParams, model: Model): Promise<z.infer<Model> | null>;
227
232
  /**
228
- * Wrapper around {@link callAsync} that validates that the returned data
229
- * matches the given validation model. Returns only the rows.
233
+ * Wrapper around {@link callAsync} that parses the resulting rows with the
234
+ * given Zod schema. Returns only the rows.
230
235
  */
231
236
  callValidatedRows<Model extends z.ZodTypeAny>(sprocName: string, params: any[], model: Model): Promise<z.infer<Model>[]>;
232
237
  /**
233
- * Wrapper around {@link callOneRowAsync} that validates that the returned data
234
- * matches the given validation model. Returns only a single row.
238
+ * Wrapper around {@link callOneRowAsync} that parses the resulting rows with
239
+ * the given Zod schema. Returns only a single row.
235
240
  */
236
241
  callValidatedOneRow<Model extends z.ZodTypeAny>(sprocName: string, params: any[], model: Model): Promise<z.infer<Model>>;
237
242
  /**
238
- * Wrapper around {@link callZeroOrOneRowAsync} that validates that the
239
- * returned data matches the given validation model, if it return anything.
240
- * Returns at most a single row.
243
+ * Wrapper around {@link callZeroOrOneRowAsync} that parses the resulting row
244
+ * (if any) with the given Zod schema. Returns at most a single row.
241
245
  */
242
246
  callValidatedZeroOrOneRow<Model extends z.ZodTypeAny>(sprocName: string, params: any[], model: Model): Promise<z.infer<Model> | null>;
247
+ /**
248
+ * Returns a {@link Cursor} for the given query. The cursor can be used to
249
+ * read results in batches, which is useful for large result sets.
250
+ */
251
+ queryCursorWithClient(client: pg.PoolClient, sql: string, params: QueryParams): Promise<Cursor>;
252
+ /**
253
+ * Returns an {@link CursorIterator} that can be used to iterate over the
254
+ * results of the query in batches, which is useful for large result sets.
255
+ */
256
+ queryCursor<Model extends z.ZodTypeAny>(sql: string, params: QueryParams): Promise<CursorIterator<z.infer<Model>>>;
257
+ /**
258
+ * Returns an {@link CursorIterator} that can be used to iterate over the
259
+ * results of the query in batches, which is useful for large result sets.
260
+ * Each row will be parsed by the given Zod schema.
261
+ */
262
+ queryValidatedCursor<Model extends z.ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<CursorIterator<z.infer<Model>>>;
263
+ private queryValidatedCursorInternal;
243
264
  /**
244
265
  * Set the schema to use for the search path.
245
266
  *
@@ -263,5 +284,12 @@ export declare class PostgresPool {
263
284
  * Generate, set, and return a random schema name.
264
285
  */
265
286
  setRandomSearchSchema: (arg1: string, callback: (err: NodeJS.ErrnoException, result: string) => void) => void;
287
+ /** The number of established connections. */
288
+ get totalCount(): number;
289
+ /** The number of idle connections. */
290
+ get idleCount(): number;
291
+ /** The number of queries waiting for a connection to become available. */
292
+ get waitingCount(): number;
293
+ /** The total number of queries that have been executed by this pool. */
294
+ get queryCount(): number;
266
295
  }
267
- export {};