@prairielearn/postgres 3.0.0 → 4.0.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
+ ## 4.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - cd5ed49: `queryCursor` was removed, and now requires a Zod schema. `queryValidatedCursor` was renamed to `queryCursor`.
8
+ - 2c19e43: - Remove callback-based query functions.
9
+ - Deprecate query functions with Zod-validated alternatives.
10
+
11
+ ### Patch Changes
12
+
13
+ - 23adb05: Upgrade all JavaScript dependencies
14
+
3
15
  ## 3.0.0
4
16
 
5
17
  ### Major Changes
package/README.md CHANGED
@@ -179,30 +179,16 @@ const { user, course } = await sqldb.runInTransactionAsync(async () => {
179
179
 
180
180
  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.
181
181
 
182
- ```ts
183
- import { queryCursor } from '@prairielearn/postgres';
184
-
185
- const cursor = await queryCursor(sql.select_all_users, {});
186
- for await (const users of cursor.iterate(100)) {
187
- // `users` will have up to 100 rows in it.
188
- for (const user of users) {
189
- console.log(user);
190
- }
191
- }
192
- ```
193
-
194
- You can optionally pass a Zod schema to parse and validate each row:
195
-
196
182
  ```ts
197
183
  import { z } from 'zod';
198
- import { queryValidatedCursor } from '@prairielearn/postgres';
184
+ import { queryCursor } from '@prairielearn/postgres';
199
185
 
200
186
  const UserSchema = z.object({
201
187
  id: z.string(),
202
188
  name: z.string(),
203
189
  });
204
190
 
205
- const cursor = await queryValidatedCursor(sql.select_all_users, {}, UserSchema);
191
+ const cursor = await queryCursor(sql.select_all_users, {}, UserSchema);
206
192
  for await (const users of cursor.iterate(100)) {
207
193
  for (const user of users) {
208
194
  console.log(user);
@@ -213,12 +199,16 @@ for await (const users of cursor.iterate(100)) {
213
199
  You can also use `cursor.stream(...)` to get an object stream, which can be useful for piping it somewhere else:
214
200
 
215
201
  ```ts
216
- import { queryCursor } from '@prairielearn/postgres';
217
-
218
- const cursor = await queryCursor(sql.select_all_users, {});
202
+ const cursor = await queryCursor(sql.select_all_users, {}, UserSchema);
219
203
  cursor.stream(100).pipe(makeStreamSomehow());
220
204
  ```
221
205
 
206
+ If you don't need to parse and validate each row with Zod, you can use `z.unknown()` as the schema:
207
+
208
+ ```ts
209
+ const cursor = await queryCursor(sql.select_all_users, {}, z.unknown());
210
+ ```
211
+
222
212
  ### Callback-style functions
223
213
 
224
214
  For most functions that return promises, there are corresponding versions that work with Node-style callbacks:
@@ -1,70 +1,185 @@
1
1
  import { type CursorIterator, PostgresPool, type QueryParams } from './pool.js';
2
2
  declare const defaultPool: PostgresPool;
3
3
  export { defaultPool, type CursorIterator, type QueryParams };
4
- export declare const init: (arg1: import("./pool.js").PostgresPoolConfig, arg2: (error: Error, client: import("pg").default.PoolClient) => void, callback: (err: NodeJS.ErrnoException) => void) => void;
4
+ /**
5
+ * Creates a new connection pool and attempts to connect to the database.
6
+ */
5
7
  export declare const initAsync: (pgConfig: import("./pool.js").PostgresPoolConfig, idleErrorHandler: (error: Error, client: import("pg").default.PoolClient) => void) => Promise<void>;
6
- export declare const close: (callback: (err: NodeJS.ErrnoException) => void) => void;
8
+ /**
9
+ * Closes the connection pool.
10
+ */
7
11
  export declare const closeAsync: () => Promise<void>;
12
+ /**
13
+ * Gets a new client from the connection pool. The caller MUST call `release()` to
14
+ * release the client, whether or not errors occurred while using
15
+ * `client`. The client can call `done(truthy_value)` to force
16
+ * destruction of the client, but this should not be used except in
17
+ * unusual circumstances.
18
+ */
8
19
  export declare const getClientAsync: () => Promise<import("pg").default.PoolClient>;
9
- export declare const getClient: (callback: (error: Error | null, client?: import("pg").default.PoolClient, done?: () => void) => void) => void;
10
- export declare const queryWithClient: (arg1: import("pg").PoolClient, arg2: string, arg3: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
20
+ /**
21
+ * Performs a query with the given client.
22
+ */
11
23
  export declare const queryWithClientAsync: (client: import("pg").default.PoolClient, sql: string, params: QueryParams) => Promise<import("pg").default.QueryResult>;
12
- export declare const queryWithClientOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
24
+ /**
25
+ * Performs a query with the given client. Errors if the query returns more
26
+ * than one row.
27
+ */
13
28
  export declare const queryWithClientOneRowAsync: (client: import("pg").default.PoolClient, sql: string, params: QueryParams) => Promise<import("pg").default.QueryResult>;
14
- export declare const queryWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
29
+ /**
30
+ * Performs a query with the given client. Errors if the query returns more
31
+ * than one row.
32
+ */
15
33
  export declare const queryWithClientZeroOrOneRowAsync: (client: import("pg").default.PoolClient, sql: string, params: QueryParams) => Promise<import("pg").QueryResult>;
34
+ /**
35
+ * Rolls back the current transaction for the given client.
36
+ */
16
37
  export declare const rollbackWithClientAsync: (client: import("pg").default.PoolClient) => Promise<void>;
17
- export declare const rollbackWithClient: (client: import("pg").default.PoolClient, _done: (release?: any) => void, callback: (err: Error | null) => void) => void;
18
38
  export declare const beginTransactionAsync: () => Promise<import("pg").default.PoolClient>;
39
+ /**
40
+ * Commits the transaction if err is null, otherwise rollbacks the transaction.
41
+ * Also releases the client.
42
+ */
19
43
  export declare const endTransactionAsync: (client: import("pg").default.PoolClient, err: Error | null | undefined) => Promise<void>;
20
- export declare const endTransaction: (client: import("pg").default.PoolClient, _done: (rollback?: any) => void, err: Error | null | undefined, callback: (error: Error | null) => void) => void;
44
+ /**
45
+ * Runs the specified function inside of a transaction. The function will
46
+ * receive a database client as an argument, but it can also make queries
47
+ * as usual, and the correct client will be used automatically.
48
+ *
49
+ * The transaction will be rolled back if the function throws an error, and
50
+ * will be committed otherwise.
51
+ */
21
52
  export declare const runInTransactionAsync: <T>(fn: (client: import("pg").default.PoolClient) => Promise<T>) => Promise<T>;
22
- export declare const query: (arg1: string, arg2: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").QueryResult<any>) => void) => void;
53
+ /**
54
+ * Executes a query with the specified parameters.
55
+ *
56
+ * Using the return value of this function directly is not recommended. Instead, use
57
+ * {@link queryRows}, {@link queryRow}, or {@link queryOptionalRow}.
58
+ */
23
59
  export declare const queryAsync: (sql: string, params: QueryParams) => Promise<import("pg").QueryResult>;
24
- export declare const queryOneRow: (arg1: string, arg2: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
60
+ /**
61
+ * Executes a query with the specified parameters. Errors if the query does
62
+ * not return exactly one row.
63
+ *
64
+ * @deprecated Use {@link queryRow} instead.
65
+ */
25
66
  export declare const queryOneRowAsync: (sql: string, params: QueryParams) => Promise<import("pg").default.QueryResult>;
26
- export declare const queryZeroOrOneRow: (arg1: string, arg2: QueryParams, callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
67
+ /**
68
+ * Executes a query with the specified parameters. Errors if the query
69
+ * returns more than one row.
70
+ *
71
+ * @deprecated Use {@link queryOptionalRow} instead.
72
+ */
27
73
  export declare const queryZeroOrOneRowAsync: (sql: string, params: QueryParams) => Promise<import("pg").default.QueryResult>;
28
- export declare const call: (arg1: string, arg2: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
74
+ /**
75
+ * Calls the given sproc with the specified parameters.
76
+ *
77
+ * @deprecated Use {@link callRows} instead.
78
+ */
29
79
  export declare const callAsync: (functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
30
- export declare const callOneRow: (arg1: string, arg2: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
80
+ /**
81
+ * Calls the given sproc with the specified parameters. Errors if the
82
+ * sproc does not return exactly one row.
83
+ *
84
+ * @deprecated Use {@link callRow} instead.
85
+ */
31
86
  export declare const callOneRowAsync: (functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
32
- export declare const callZeroOrOneRow: (arg1: string, arg2: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
87
+ /**
88
+ * Calls the given sproc with the specified parameters. Errors if the
89
+ * sproc returns more than one row.
90
+ *
91
+ * @deprecated Use {@link callOptionalRow} instead.
92
+ */
33
93
  export declare const callZeroOrOneRowAsync: (functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
34
- export declare const callWithClient: (arg1: import("pg").PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
94
+ /**
95
+ * Calls a sproc with the specified parameters using a specific client.
96
+ */
35
97
  export declare const callWithClientAsync: (client: import("pg").default.PoolClient, functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
36
- export declare const callWithClientOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
98
+ /**
99
+ * Calls a sproc with the specified parameters using a specific client.
100
+ * Errors if the sproc does not return exactly one row.
101
+ */
37
102
  export declare const callWithClientOneRowAsync: (client: import("pg").default.PoolClient, functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
38
- export declare const callWithClientZeroOrOneRow: (arg1: import("pg").PoolClient, arg2: string, arg3: any[], callback: (err: NodeJS.ErrnoException | null, result: import("pg").default.QueryResult<any>) => void) => void;
103
+ /**
104
+ * Calls a sproc with the specified parameters using a specific client.
105
+ * Errors if the sproc returns more than one row.
106
+ */
39
107
  export declare const callWithClientZeroOrOneRowAsync: (client: import("pg").default.PoolClient, functionName: string, params: any[]) => Promise<import("pg").default.QueryResult>;
108
+ /**
109
+ * Executes a query with the specified parameters. Returns an array of rows
110
+ * that conform to the given Zod schema.
111
+ *
112
+ * If the query returns a single column, the return value will be a list of column values.
113
+ */
40
114
  export declare const queryRows: {
41
115
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
42
116
  <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>[]>;
43
117
  };
118
+ /**
119
+ * Executes a query with the specified parameters. Returns exactly one row that conforms to the given Zod schema.
120
+ *
121
+ * If the query returns a single column, the return value will be the column value itself.
122
+ */
44
123
  export declare const queryRow: {
45
124
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>>;
46
125
  <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>>;
47
126
  };
127
+ /**
128
+ * Executes a query with the specified parameters. Returns either null or a
129
+ * single row that conforms to the given Zod schema, and errors otherwise.
130
+ *
131
+ * If the query returns a single column, the return value will be the column value itself.
132
+ */
48
133
  export declare const queryOptionalRow: {
49
134
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model> | null>;
50
135
  <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model> | null>;
51
136
  };
137
+ /**
138
+ * Calls the given sproc with the specified parameters.
139
+ * Errors if the sproc does not return anything.
140
+ */
52
141
  export declare const callRows: {
53
142
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
54
143
  <Model extends import("zod").ZodTypeAny>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model>[]>;
55
144
  };
145
+ /**
146
+ * Calls the given sproc with the specified parameters.
147
+ * Returns exactly one row from the sproc that conforms to the given Zod schema.
148
+ */
56
149
  export declare const callRow: {
57
150
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>>;
58
151
  <Model extends import("zod").ZodTypeAny>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model>>;
59
152
  };
153
+ /**
154
+ * Calls the given sproc with the specified parameters. Returns either null
155
+ * or a single row that conforms to the given Zod schema.
156
+ */
60
157
  export declare const callOptionalRow: {
61
158
  <Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model> | null>;
62
159
  <Model extends import("zod").ZodTypeAny>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model> | null>;
63
160
  };
64
- export declare const queryCursorWithClient: (client: import("pg").default.PoolClient, sql: string, params: QueryParams) => Promise<import("pg-cursor")>;
65
- export declare const queryCursor: <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams) => Promise<CursorIterator<import("zod").TypeOf<Model>>>;
66
- export declare const queryValidatedCursor: <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model) => Promise<CursorIterator<import("zod").TypeOf<Model>>>;
161
+ /**
162
+ * Returns an {@link CursorIterator} that can be used to iterate over the
163
+ * results of the query in batches, which is useful for large result sets.
164
+ * Each row will be parsed by the given Zod schema.
165
+ */
166
+ export declare const queryCursor: <Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model) => Promise<CursorIterator<import("zod").TypeOf<Model>>>;
167
+ /**
168
+ * Set the schema to use for the search path.
169
+ *
170
+ * @param schema The schema name to use (can be "null" to unset the search path)
171
+ */
67
172
  export declare const setSearchSchema: (schema: string) => Promise<void>;
173
+ /**
174
+ * Get the schema that is currently used for the search path.
175
+ *
176
+ * @return schema in use (may be `null` to indicate no schema)
177
+ */
68
178
  export declare const getSearchSchema: () => string | null;
69
- export declare const setRandomSearchSchema: (arg1: string, callback: (err: NodeJS.ErrnoException, result: string) => void) => void;
179
+ /**
180
+ * Generate, set, and return a random schema name.
181
+ *
182
+ * @param prefix The prefix of the new schema, only the first 28 characters will be used (after lowercasing).
183
+ * @returns The randomly-generated search schema.
184
+ */
70
185
  export declare const setRandomSearchSchemaAsync: (prefix: string) => Promise<string>;
@@ -9,53 +9,171 @@ export { defaultPool };
9
9
  // that they'll be invoked with the correct `this` context, specifically when
10
10
  // this module is imported as `import * as db from '...'` and that import is
11
11
  // subsequently transformed by Babel to `interopRequireWildcard(...)`.
12
- export const init = defaultPool.init.bind(defaultPool);
12
+ // VSCode currently doesn't allow for us to use `inheritDoc` to inherit the
13
+ // documentation from the `PostgresPool` class. We mirror the documentation
14
+ // here for *async methods* in VSCode intellisense.
15
+ /**
16
+ * Creates a new connection pool and attempts to connect to the database.
17
+ */
13
18
  export const initAsync = defaultPool.initAsync.bind(defaultPool);
14
- export const close = defaultPool.close.bind(defaultPool);
19
+ /**
20
+ * Closes the connection pool.
21
+ */
15
22
  export const closeAsync = defaultPool.closeAsync.bind(defaultPool);
23
+ /**
24
+ * Gets a new client from the connection pool. The caller MUST call `release()` to
25
+ * release the client, whether or not errors occurred while using
26
+ * `client`. The client can call `done(truthy_value)` to force
27
+ * destruction of the client, but this should not be used except in
28
+ * unusual circumstances.
29
+ */
16
30
  export const getClientAsync = defaultPool.getClientAsync.bind(defaultPool);
17
- export const getClient = defaultPool.getClient.bind(defaultPool);
18
- export const queryWithClient = defaultPool.queryWithClient.bind(defaultPool);
31
+ /**
32
+ * Performs a query with the given client.
33
+ */
19
34
  export const queryWithClientAsync = defaultPool.queryWithClientAsync.bind(defaultPool);
20
- export const queryWithClientOneRow = defaultPool.queryWithClientOneRow.bind(defaultPool);
35
+ /**
36
+ * Performs a query with the given client. Errors if the query returns more
37
+ * than one row.
38
+ */
21
39
  export const queryWithClientOneRowAsync = defaultPool.queryWithClientOneRowAsync.bind(defaultPool);
22
- export const queryWithClientZeroOrOneRow = defaultPool.queryWithClientZeroOrOneRow.bind(defaultPool);
40
+ /**
41
+ * Performs a query with the given client. Errors if the query returns more
42
+ * than one row.
43
+ */
23
44
  export const queryWithClientZeroOrOneRowAsync = defaultPool.queryWithClientZeroOrOneRowAsync.bind(defaultPool);
45
+ /**
46
+ * Rolls back the current transaction for the given client.
47
+ */
24
48
  export const rollbackWithClientAsync = defaultPool.rollbackWithClientAsync.bind(defaultPool);
25
- export const rollbackWithClient = defaultPool.rollbackWithClient.bind(defaultPool);
26
49
  export const beginTransactionAsync = defaultPool.beginTransactionAsync.bind(defaultPool);
50
+ /**
51
+ * Commits the transaction if err is null, otherwise rollbacks the transaction.
52
+ * Also releases the client.
53
+ */
27
54
  export const endTransactionAsync = defaultPool.endTransactionAsync.bind(defaultPool);
28
- export const endTransaction = defaultPool.endTransaction.bind(defaultPool);
55
+ /**
56
+ * Runs the specified function inside of a transaction. The function will
57
+ * receive a database client as an argument, but it can also make queries
58
+ * as usual, and the correct client will be used automatically.
59
+ *
60
+ * The transaction will be rolled back if the function throws an error, and
61
+ * will be committed otherwise.
62
+ */
29
63
  export const runInTransactionAsync = defaultPool.runInTransactionAsync.bind(defaultPool);
30
- export const query = defaultPool.query.bind(defaultPool);
64
+ /**
65
+ * Executes a query with the specified parameters.
66
+ *
67
+ * Using the return value of this function directly is not recommended. Instead, use
68
+ * {@link queryRows}, {@link queryRow}, or {@link queryOptionalRow}.
69
+ */
31
70
  export const queryAsync = defaultPool.queryAsync.bind(defaultPool);
32
- export const queryOneRow = defaultPool.queryOneRow.bind(defaultPool);
71
+ /**
72
+ * Executes a query with the specified parameters. Errors if the query does
73
+ * not return exactly one row.
74
+ *
75
+ * @deprecated Use {@link queryRow} instead.
76
+ */
33
77
  export const queryOneRowAsync = defaultPool.queryOneRowAsync.bind(defaultPool);
34
- export const queryZeroOrOneRow = defaultPool.queryZeroOrOneRow.bind(defaultPool);
78
+ /**
79
+ * Executes a query with the specified parameters. Errors if the query
80
+ * returns more than one row.
81
+ *
82
+ * @deprecated Use {@link queryOptionalRow} instead.
83
+ */
35
84
  export const queryZeroOrOneRowAsync = defaultPool.queryZeroOrOneRowAsync.bind(defaultPool);
36
- export const call = defaultPool.call.bind(defaultPool);
85
+ /**
86
+ * Calls the given sproc with the specified parameters.
87
+ *
88
+ * @deprecated Use {@link callRows} instead.
89
+ */
37
90
  export const callAsync = defaultPool.callAsync.bind(defaultPool);
38
- export const callOneRow = defaultPool.callOneRow.bind(defaultPool);
91
+ /**
92
+ * Calls the given sproc with the specified parameters. Errors if the
93
+ * sproc does not return exactly one row.
94
+ *
95
+ * @deprecated Use {@link callRow} instead.
96
+ */
39
97
  export const callOneRowAsync = defaultPool.callOneRowAsync.bind(defaultPool);
40
- export const callZeroOrOneRow = defaultPool.callZeroOrOneRow.bind(defaultPool);
98
+ /**
99
+ * Calls the given sproc with the specified parameters. Errors if the
100
+ * sproc returns more than one row.
101
+ *
102
+ * @deprecated Use {@link callOptionalRow} instead.
103
+ */
41
104
  export const callZeroOrOneRowAsync = defaultPool.callZeroOrOneRowAsync.bind(defaultPool);
42
- export const callWithClient = defaultPool.callWithClient.bind(defaultPool);
105
+ /**
106
+ * Calls a sproc with the specified parameters using a specific client.
107
+ */
43
108
  export const callWithClientAsync = defaultPool.callWithClientAsync.bind(defaultPool);
44
- export const callWithClientOneRow = defaultPool.callWithClientOneRow.bind(defaultPool);
109
+ /**
110
+ * Calls a sproc with the specified parameters using a specific client.
111
+ * Errors if the sproc does not return exactly one row.
112
+ */
45
113
  export const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.bind(defaultPool);
46
- export const callWithClientZeroOrOneRow = defaultPool.callWithClientZeroOrOneRow.bind(defaultPool);
114
+ /**
115
+ * Calls a sproc with the specified parameters using a specific client.
116
+ * Errors if the sproc returns more than one row.
117
+ */
47
118
  export const callWithClientZeroOrOneRowAsync = defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);
119
+ /**
120
+ * Executes a query with the specified parameters. Returns an array of rows
121
+ * that conform to the given Zod schema.
122
+ *
123
+ * If the query returns a single column, the return value will be a list of column values.
124
+ */
48
125
  export const queryRows = defaultPool.queryRows.bind(defaultPool);
126
+ /**
127
+ * Executes a query with the specified parameters. Returns exactly one row that conforms to the given Zod schema.
128
+ *
129
+ * If the query returns a single column, the return value will be the column value itself.
130
+ */
49
131
  export const queryRow = defaultPool.queryRow.bind(defaultPool);
132
+ /**
133
+ * Executes a query with the specified parameters. Returns either null or a
134
+ * single row that conforms to the given Zod schema, and errors otherwise.
135
+ *
136
+ * If the query returns a single column, the return value will be the column value itself.
137
+ */
50
138
  export const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);
139
+ /**
140
+ * Calls the given sproc with the specified parameters.
141
+ * Errors if the sproc does not return anything.
142
+ */
51
143
  export const callRows = defaultPool.callRows.bind(defaultPool);
144
+ /**
145
+ * Calls the given sproc with the specified parameters.
146
+ * Returns exactly one row from the sproc that conforms to the given Zod schema.
147
+ */
52
148
  export const callRow = defaultPool.callRow.bind(defaultPool);
149
+ /**
150
+ * Calls the given sproc with the specified parameters. Returns either null
151
+ * or a single row that conforms to the given Zod schema.
152
+ */
53
153
  export const callOptionalRow = defaultPool.callOptionalRow.bind(defaultPool);
54
- export const queryCursorWithClient = defaultPool.queryCursorWithClient.bind(defaultPool);
154
+ /**
155
+ * Returns an {@link CursorIterator} that can be used to iterate over the
156
+ * results of the query in batches, which is useful for large result sets.
157
+ * Each row will be parsed by the given Zod schema.
158
+ */
55
159
  export const queryCursor = defaultPool.queryCursor.bind(defaultPool);
56
- export const queryValidatedCursor = defaultPool.queryValidatedCursor.bind(defaultPool);
160
+ /**
161
+ * Set the schema to use for the search path.
162
+ *
163
+ * @param schema The schema name to use (can be "null" to unset the search path)
164
+ */
57
165
  export const setSearchSchema = defaultPool.setSearchSchema.bind(defaultPool);
166
+ /**
167
+ * Get the schema that is currently used for the search path.
168
+ *
169
+ * @return schema in use (may be `null` to indicate no schema)
170
+ */
58
171
  export const getSearchSchema = defaultPool.getSearchSchema.bind(defaultPool);
59
- export const setRandomSearchSchema = defaultPool.setRandomSearchSchema.bind(defaultPool);
172
+ /**
173
+ * Generate, set, and return a random schema name.
174
+ *
175
+ * @param prefix The prefix of the new schema, only the first 28 characters will be used (after lowercasing).
176
+ * @returns The randomly-generated search schema.
177
+ */
60
178
  export const setRandomSearchSchemaAsync = defaultPool.setRandomSearchSchemaAsync.bind(defaultPool);
61
179
  //# sourceMappingURL=default-pool.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"default-pool.js","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAoB,MAAM,WAAW,CAAC;AAEhF,MAAM,WAAW,GAAG,IAAI,YAAY,EAAE,CAAC;AACvC,OAAO,EAAE,WAAW,EAAyC,CAAC;AAE9D,2EAA2E;AAC3E,6EAA6E;AAC7E,sDAAsD;AACtD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AACtE,MAAM,CAAC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvD,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,KAAK,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACvF,MAAM,CAAC,MAAM,qBAAqB,GAAG,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACzF,MAAM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B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import { type CursorIterator, PostgresPool, type QueryParams } from './pool.js';\n\nconst defaultPool = new PostgresPool();\nexport { defaultPool, type CursorIterator, type QueryParams };\n\n// We re-expose all functions from the default pool here to account for the\n// default case of a shared global pool of clients. If someone want to create\n// their own pool, we expose the `PostgresPool` class.\n//\n// Note that we explicitly bind all functions to `defaultPool`. This ensures\n// that they'll be invoked with the correct `this` context, specifically when\n// this module is imported as `import * as db from '...'` and that import is\n// subsequently transformed by Babel to `interopRequireWildcard(...)`.\nexport const init = defaultPool.init.bind(defaultPool);\nexport const initAsync = defaultPool.initAsync.bind(defaultPool);\nexport const close = defaultPool.close.bind(defaultPool);\nexport const closeAsync = defaultPool.closeAsync.bind(defaultPool);\nexport const getClientAsync = defaultPool.getClientAsync.bind(defaultPool);\nexport const getClient = defaultPool.getClient.bind(defaultPool);\nexport const queryWithClient = defaultPool.queryWithClient.bind(defaultPool);\nexport const queryWithClientAsync = defaultPool.queryWithClientAsync.bind(defaultPool);\nexport const queryWithClientOneRow = defaultPool.queryWithClientOneRow.bind(defaultPool);\nexport const queryWithClientOneRowAsync = defaultPool.queryWithClientOneRowAsync.bind(defaultPool);\nexport const queryWithClientZeroOrOneRow =\n defaultPool.queryWithClientZeroOrOneRow.bind(defaultPool);\nexport const queryWithClientZeroOrOneRowAsync =\n defaultPool.queryWithClientZeroOrOneRowAsync.bind(defaultPool);\nexport const rollbackWithClientAsync = defaultPool.rollbackWithClientAsync.bind(defaultPool);\nexport const rollbackWithClient = defaultPool.rollbackWithClient.bind(defaultPool);\nexport const beginTransactionAsync = defaultPool.beginTransactionAsync.bind(defaultPool);\nexport const endTransactionAsync = defaultPool.endTransactionAsync.bind(defaultPool);\nexport const endTransaction = defaultPool.endTransaction.bind(defaultPool);\nexport const runInTransactionAsync = defaultPool.runInTransactionAsync.bind(defaultPool);\nexport const query = defaultPool.query.bind(defaultPool);\nexport const queryAsync = defaultPool.queryAsync.bind(defaultPool);\nexport const queryOneRow = defaultPool.queryOneRow.bind(defaultPool);\nexport const queryOneRowAsync = defaultPool.queryOneRowAsync.bind(defaultPool);\nexport const queryZeroOrOneRow = defaultPool.queryZeroOrOneRow.bind(defaultPool);\nexport const queryZeroOrOneRowAsync = defaultPool.queryZeroOrOneRowAsync.bind(defaultPool);\nexport const call = defaultPool.call.bind(defaultPool);\nexport const callAsync = defaultPool.callAsync.bind(defaultPool);\nexport const callOneRow = defaultPool.callOneRow.bind(defaultPool);\nexport const callOneRowAsync = defaultPool.callOneRowAsync.bind(defaultPool);\nexport const callZeroOrOneRow = defaultPool.callZeroOrOneRow.bind(defaultPool);\nexport const callZeroOrOneRowAsync = defaultPool.callZeroOrOneRowAsync.bind(defaultPool);\nexport const callWithClient = defaultPool.callWithClient.bind(defaultPool);\nexport const callWithClientAsync = defaultPool.callWithClientAsync.bind(defaultPool);\nexport const callWithClientOneRow = defaultPool.callWithClientOneRow.bind(defaultPool);\nexport const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.bind(defaultPool);\nexport const callWithClientZeroOrOneRow = defaultPool.callWithClientZeroOrOneRow.bind(defaultPool);\nexport const callWithClientZeroOrOneRowAsync =\n defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);\nexport const queryRows = defaultPool.queryRows.bind(defaultPool);\nexport const queryRow = defaultPool.queryRow.bind(defaultPool);\nexport const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);\nexport const callRows = defaultPool.callRows.bind(defaultPool);\nexport const callRow = defaultPool.callRow.bind(defaultPool);\nexport const callOptionalRow = defaultPool.callOptionalRow.bind(defaultPool);\nexport const queryCursorWithClient = defaultPool.queryCursorWithClient.bind(defaultPool);\nexport const queryCursor = defaultPool.queryCursor.bind(defaultPool);\nexport const queryValidatedCursor = defaultPool.queryValidatedCursor.bind(defaultPool);\nexport const setSearchSchema = defaultPool.setSearchSchema.bind(defaultPool);\nexport const getSearchSchema = defaultPool.getSearchSchema.bind(defaultPool);\nexport const setRandomSearchSchema = defaultPool.setRandomSearchSchema.bind(defaultPool);\nexport const setRandomSearchSchemaAsync = defaultPool.setRandomSearchSchemaAsync.bind(defaultPool);\n"]}
1
+ {"version":3,"file":"default-pool.js","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,YAAY,EAAoB,MAAM,WAAW,CAAC;AAEhF,MAAM,WAAW,GAAG,IAAI,YAAY,EAAE,CAAC;AACvC,OAAO,EAAE,WAAW,EAAyC,CAAC;AAE9D,2EAA2E;AAC3E,6EAA6E;AAC7E,sDAAsD;AACtD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,4EAA4E;AAC5E,sEAAsE;AAEtE,2EAA2E;AAC3E,2EAA2E;AAC3E,mDAAmD;AAEnD;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjE;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAE3E;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEvF;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEnG;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAC3C,WAAW,CAAC,gCAAgC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjE;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,WAAW,CAAC,uBAAuB,CAAC,IAAI,CAAC,WAAW,CA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+BAA+B,GAC1C,WAAW,CAAC,+BAA+B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAChE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACjE;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/E;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/D;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7D;;;GAGG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACrE;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC7E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC","sourcesContent":["import { type CursorIterator, PostgresPool, type QueryParams } from './pool.js';\n\nconst defaultPool = new PostgresPool();\nexport { defaultPool, type CursorIterator, type QueryParams };\n\n// We re-expose all functions from the default pool here to account for the\n// default case of a shared global pool of clients. If someone want to create\n// their own pool, we expose the `PostgresPool` class.\n//\n// Note that we explicitly bind all functions to `defaultPool`. This ensures\n// that they'll be invoked with the correct `this` context, specifically when\n// this module is imported as `import * as db from '...'` and that import is\n// subsequently transformed by Babel to `interopRequireWildcard(...)`.\n\n// VSCode currently doesn't allow for us to use `inheritDoc` to inherit the\n// documentation from the `PostgresPool` class. We mirror the documentation\n// here for *async methods* in VSCode intellisense.\n\n/**\n * Creates a new connection pool and attempts to connect to the database.\n */\nexport const initAsync = defaultPool.initAsync.bind(defaultPool);\n/**\n * Closes the connection pool.\n */\nexport const closeAsync = defaultPool.closeAsync.bind(defaultPool);\n/**\n * Gets a new client from the connection pool. The caller MUST call `release()` to\n * release the client, whether or not errors occurred while using\n * `client`. The client can call `done(truthy_value)` to force\n * destruction of the client, but this should not be used except in\n * unusual circumstances.\n */\nexport const getClientAsync = defaultPool.getClientAsync.bind(defaultPool);\n\n/**\n * Performs a query with the given client.\n */\nexport const queryWithClientAsync = defaultPool.queryWithClientAsync.bind(defaultPool);\n\n/**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\nexport const queryWithClientOneRowAsync = defaultPool.queryWithClientOneRowAsync.bind(defaultPool);\n\n/**\n * Performs a query with the given client. Errors if the query returns more\n * than one row.\n */\nexport const queryWithClientZeroOrOneRowAsync =\n defaultPool.queryWithClientZeroOrOneRowAsync.bind(defaultPool);\n/**\n * Rolls back the current transaction for the given client.\n */\nexport const rollbackWithClientAsync = defaultPool.rollbackWithClientAsync.bind(defaultPool);\nexport const beginTransactionAsync = defaultPool.beginTransactionAsync.bind(defaultPool);\n/**\n * Commits the transaction if err is null, otherwise rollbacks the transaction.\n * Also releases the client.\n */\nexport const endTransactionAsync = defaultPool.endTransactionAsync.bind(defaultPool);\n/**\n * Runs the specified function inside of a transaction. The function will\n * receive a database client as an argument, but it can also make queries\n * as usual, and the correct client will be used automatically.\n *\n * The transaction will be rolled back if the function throws an error, and\n * will be committed otherwise.\n */\nexport const runInTransactionAsync = defaultPool.runInTransactionAsync.bind(defaultPool);\n/**\n * Executes a query with the specified parameters.\n *\n * Using the return value of this function directly is not recommended. Instead, use\n * {@link queryRows}, {@link queryRow}, or {@link queryOptionalRow}.\n */\nexport const queryAsync = defaultPool.queryAsync.bind(defaultPool);\n/**\n * Executes a query with the specified parameters. Errors if the query does\n * not return exactly one row.\n *\n * @deprecated Use {@link queryRow} instead.\n */\nexport const queryOneRowAsync = defaultPool.queryOneRowAsync.bind(defaultPool);\n/**\n * Executes a query with the specified parameters. Errors if the query\n * returns more than one row.\n *\n * @deprecated Use {@link queryOptionalRow} instead.\n */\nexport const queryZeroOrOneRowAsync = defaultPool.queryZeroOrOneRowAsync.bind(defaultPool);\n/**\n * Calls the given sproc with the specified parameters.\n *\n * @deprecated Use {@link callRows} instead.\n */\nexport const callAsync = defaultPool.callAsync.bind(defaultPool);\n/**\n * Calls the given sproc with the specified parameters. Errors if the\n * sproc does not return exactly one row.\n *\n * @deprecated Use {@link callRow} instead.\n */\nexport const callOneRowAsync = defaultPool.callOneRowAsync.bind(defaultPool);\n/**\n * Calls the given sproc with the specified parameters. Errors if the\n * sproc returns more than one row.\n *\n * @deprecated Use {@link callOptionalRow} instead.\n */\nexport const callZeroOrOneRowAsync = defaultPool.callZeroOrOneRowAsync.bind(defaultPool);\n/**\n * Calls a sproc with the specified parameters using a specific client.\n */\nexport const callWithClientAsync = defaultPool.callWithClientAsync.bind(defaultPool);\n/**\n * Calls a sproc with the specified parameters using a specific client.\n * Errors if the sproc does not return exactly one row.\n */\nexport const callWithClientOneRowAsync = defaultPool.callWithClientOneRowAsync.bind(defaultPool);\n/**\n * Calls a sproc with the specified parameters using a specific client.\n * Errors if the sproc returns more than one row.\n */\nexport const callWithClientZeroOrOneRowAsync =\n defaultPool.callWithClientZeroOrOneRowAsync.bind(defaultPool);\n/**\n * Executes a query with the specified parameters. Returns an array of rows\n * that conform to the given Zod schema.\n *\n * If the query returns a single column, the return value will be a list of column values.\n */\nexport const queryRows = defaultPool.queryRows.bind(defaultPool);\n/**\n * Executes a query with the specified parameters. Returns exactly one row that conforms to the given Zod schema.\n *\n * If the query returns a single column, the return value will be the column value itself.\n */\nexport const queryRow = defaultPool.queryRow.bind(defaultPool);\n/**\n * Executes a query with the specified parameters. Returns either null or a\n * single row that conforms to the given Zod schema, and errors otherwise.\n *\n * If the query returns a single column, the return value will be the column value itself.\n */\nexport const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);\n/**\n * Calls the given sproc with the specified parameters.\n * Errors if the sproc does not return anything.\n */\nexport const callRows = defaultPool.callRows.bind(defaultPool);\n/**\n * Calls the given sproc with the specified parameters.\n * Returns exactly one row from the sproc that conforms to the given Zod schema.\n */\nexport const callRow = defaultPool.callRow.bind(defaultPool);\n/**\n * Calls the given sproc with the specified parameters. Returns either null\n * or a single row that conforms to the given Zod schema.\n */\nexport const callOptionalRow = defaultPool.callOptionalRow.bind(defaultPool);\n/**\n * Returns an {@link CursorIterator} that can be used to iterate over the\n * results of the query in batches, which is useful for large result sets.\n * Each row will be parsed by the given Zod schema.\n */\nexport const queryCursor = defaultPool.queryCursor.bind(defaultPool);\n/**\n * Set the schema to use for the search path.\n *\n * @param schema The schema name to use (can be \"null\" to unset the search path)\n */\nexport const setSearchSchema = defaultPool.setSearchSchema.bind(defaultPool);\n/**\n * Get the schema that is currently used for the search path.\n *\n * @return schema in use (may be `null` to indicate no schema)\n */\nexport const getSearchSchema = defaultPool.getSearchSchema.bind(defaultPool);\n/**\n * Generate, set, and return a random schema name.\n *\n * @param prefix The prefix of the new schema, only the first 28 characters will be used (after lowercasing).\n * @returns The randomly-generated search schema.\n */\nexport const setRandomSearchSchemaAsync = defaultPool.setRandomSearchSchemaAsync.bind(defaultPool);\n"]}
@@ -12,7 +12,8 @@ const HIDDEN_PROPERTIES = new Set([
12
12
  'alsClient',
13
13
  'searchSchema',
14
14
  '_queryCount',
15
- 'queryValidatedCursorInternal',
15
+ 'queryCursorWithClient',
16
+ 'queryCursorInternal',
16
17
  'errorOnUnusedParameters',
17
18
  // Getters
18
19
  'totalCount',
@@ -1 +1 @@
1
- {"version":3,"file":"default-pool.test.js","sourceRoot":"","sources":["../src/default-pool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,aAAa;IACb,kBAAkB;IAClB,MAAM;IACN,WAAW;IACX,cAAc;IACd,aAAa;IACb,8BAA8B;IAC9B,yBAAyB;IACzB,UAAU;IACV,YAAY;IACZ,WAAW;IACX,cAAc;IACd,YAAY;CACb,CAAC,CAAC;AAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QAEhC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACxC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAChB,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,EAAE,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEL,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aACpD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACxC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAChB,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,EAAE,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QAEhC,MAAM,eAAe,GAAG;YACtB,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;YACnC,GAAG,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,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, describe, it } from 'vitest';\n\nimport * as pgPool from './default-pool.js';\nimport { PostgresPool } from './pool.js';\n\n/**\n * Properties on {@link PostgresPool} that should not be available on the default\n * pool's exports.\n */\nconst HIDDEN_PROPERTIES = new Set([\n 'constructor',\n // Private members\n 'pool',\n 'alsClient',\n 'searchSchema',\n '_queryCount',\n 'queryValidatedCursorInternal',\n 'errorOnUnusedParameters',\n // Getters\n 'totalCount',\n 'idleCount',\n 'waitingCount',\n 'queryCount',\n]);\n\ndescribe('sqldb', () => {\n it('exports the full PostgresPool interface', () => {\n const pool = new PostgresPool();\n\n Object.getOwnPropertyNames(pool)\n .filter((n) => !HIDDEN_PROPERTIES.has(n))\n .forEach((prop) => {\n assert.property(pgPool, prop);\n assert.ok((pgPool as any)[prop]);\n });\n\n Object.getOwnPropertyNames(Object.getPrototypeOf(pool))\n .filter((n) => !HIDDEN_PROPERTIES.has(n))\n .forEach((prop) => {\n assert.property(pgPool, prop);\n assert.ok((pgPool as any)[prop]);\n });\n });\n\n it('should not have extra properties', () => {\n const pool = new PostgresPool();\n\n const knownProperties = [\n ...Object.getOwnPropertyNames(pool),\n ...Object.getOwnPropertyNames(Object.getPrototypeOf(pool)),\n 'PostgresPool',\n ];\n\n Object.getOwnPropertyNames(pool).forEach((prop) => {\n assert.include(knownProperties, prop);\n });\n });\n});\n"]}
1
+ {"version":3,"file":"default-pool.test.js","sourceRoot":"","sources":["../src/default-pool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE9C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,aAAa;IACb,kBAAkB;IAClB,MAAM;IACN,WAAW;IACX,cAAc;IACd,aAAa;IACb,uBAAuB;IACvB,qBAAqB;IACrB,yBAAyB;IACzB,UAAU;IACV,YAAY;IACZ,WAAW;IACX,cAAc;IACd,YAAY;CACb,CAAC,CAAC;AAEH,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE;IACrB,EAAE,CAAC,yCAAyC,EAAE,GAAG,EAAE;QACjD,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QAEhC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;aAC7B,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACxC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAChB,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,EAAE,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;QAEL,MAAM,CAAC,mBAAmB,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;aACpD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACxC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAChB,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,EAAE,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,IAAI,GAAG,IAAI,YAAY,EAAE,CAAC;QAEhC,MAAM,eAAe,GAAG;YACtB,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC;YACnC,GAAG,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,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QACxC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { assert, describe, it } from 'vitest';\n\nimport * as pgPool from './default-pool.js';\nimport { PostgresPool } from './pool.js';\n\n/**\n * Properties on {@link PostgresPool} that should not be available on the default\n * pool's exports.\n */\nconst HIDDEN_PROPERTIES = new Set([\n 'constructor',\n // Private members\n 'pool',\n 'alsClient',\n 'searchSchema',\n '_queryCount',\n 'queryCursorWithClient',\n 'queryCursorInternal',\n 'errorOnUnusedParameters',\n // Getters\n 'totalCount',\n 'idleCount',\n 'waitingCount',\n 'queryCount',\n]);\n\ndescribe('sqldb', () => {\n it('exports the full PostgresPool interface', () => {\n const pool = new PostgresPool();\n\n Object.getOwnPropertyNames(pool)\n .filter((n) => !HIDDEN_PROPERTIES.has(n))\n .forEach((prop) => {\n assert.property(pgPool, prop);\n assert.ok((pgPool as any)[prop]);\n });\n\n Object.getOwnPropertyNames(Object.getPrototypeOf(pool))\n .filter((n) => !HIDDEN_PROPERTIES.has(n))\n .forEach((prop) => {\n assert.property(pgPool, prop);\n assert.ok((pgPool as any)[prop]);\n });\n });\n\n it('should not have extra properties', () => {\n const pool = new PostgresPool();\n\n const knownProperties = [\n ...Object.getOwnPropertyNames(pool),\n ...Object.getOwnPropertyNames(Object.getPrototypeOf(pool)),\n 'PostgresPool',\n ];\n\n Object.getOwnPropertyNames(pool).forEach((prop) => {\n assert.include(knownProperties, prop);\n });\n });\n});\n"]}