@prairielearn/postgres 5.0.2 → 6.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 +17 -0
- package/README.md +30 -17
- package/dist/default-pool.d.ts +64 -61
- package/dist/default-pool.d.ts.map +1 -1
- package/dist/default-pool.js +34 -49
- package/dist/default-pool.js.map +1 -1
- package/dist/default-pool.test.d.ts.map +1 -1
- package/dist/default-pool.test.js +7 -0
- package/dist/default-pool.test.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/pool.d.ts +36 -14
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +89 -55
- package/dist/pool.js.map +1 -1
- package/dist/pool.test.d.ts.map +1 -1
- package/dist/pool.test.js +144 -25
- package/dist/pool.test.js.map +1 -1
- package/package.json +8 -8
- package/src/default-pool.test.ts +7 -0
- package/src/default-pool.ts +34 -49
- package/src/index.ts +1 -1
- package/src/pool.test.ts +202 -26
- package/src/pool.ts +212 -72
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @prairielearn/postgres
|
|
2
2
|
|
|
3
|
+
## 6.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- b7885cd: Remove deprecated untyped SQL exports: `queryAsync`, `queryOneRowAsync`, `queryZeroOrOneRowAsync`, `callAsync`, `callOneRowAsync`, `callZeroOrOneRowAsync`
|
|
8
|
+
- 2f9d39b: Require `z.object(...)` schemas in query functions (`queryRow`, `queryRows`, `queryOptionalRow`, `callRow`, `callRows`, `callOptionalRow`, `queryCursor`). Branded object schemas (via `.brand()`) are also accepted. Remove implicit single-column flattening behavior where single-column query results were automatically unwrapped. Add explicit scalar query functions (`queryScalar`, `queryScalars`, `queryOptionalScalar`, `callScalar`, `callScalars`, `callOptionalScalar`) for single-column queries that accept any Zod schema and validate the column value directly.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 3c4799a: Upgrade all JavaScript dependencies
|
|
13
|
+
|
|
14
|
+
## 5.0.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 7b937fb: Remove unused exports, add `@knipignore` for intentionally public exports, and re-export newly used symbols from `@prairielearn/formatter`.
|
|
19
|
+
|
|
3
20
|
## 5.0.2
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -139,28 +139,41 @@ const user = await callRow('select_user', ['1'], User);
|
|
|
139
139
|
const maybeUser = await callOptionalRow('select_user', ['1'], User);
|
|
140
140
|
```
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
Passing an object or array with parameters is optional.
|
|
143
143
|
|
|
144
|
-
|
|
144
|
+
The schema passed to these functions must be a `z.object(...)` schema. Each row from the query result will be validated against the schema.
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
### Scalar queries
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
-- BLOCK select_user_names
|
|
150
|
-
SELECT
|
|
151
|
-
name
|
|
152
|
-
FROM
|
|
153
|
-
users;
|
|
154
|
-
```
|
|
148
|
+
For queries that return a single column, you can use the scalar variants. These accept any Zod schema (not just `z.object(...)`) and validate the individual column value.
|
|
155
149
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
150
|
+
```ts
|
|
151
|
+
import { z } from 'zod';
|
|
152
|
+
import {
|
|
153
|
+
queryScalar,
|
|
154
|
+
queryScalars,
|
|
155
|
+
queryOptionalScalar,
|
|
156
|
+
callScalar,
|
|
157
|
+
callScalars,
|
|
158
|
+
callOptionalScalar,
|
|
159
|
+
} from '@prairielearn/postgres';
|
|
160
|
+
|
|
161
|
+
// Get all user IDs. Returns an array of strings.
|
|
162
|
+
const userIds = await queryScalars(sql.select_user_ids, z.string());
|
|
163
|
+
|
|
164
|
+
// Get one user's name. Returns a string.
|
|
165
|
+
const name = await queryScalar(sql.select_user_name, { user_id: '1' }, z.string());
|
|
166
|
+
|
|
167
|
+
// Get a count that might be null. Returns a number or null.
|
|
168
|
+
const count = await queryOptionalScalar(sql.select_count, z.coerce.number());
|
|
169
|
+
|
|
170
|
+
// Equivalent sproc variants.
|
|
171
|
+
const ids = await callScalars('get_all_ids', z.string());
|
|
172
|
+
const id = await callScalar('get_id', [1], z.string());
|
|
173
|
+
const maybeId = await callOptionalScalar('get_id', [1], z.string());
|
|
174
|
+
```
|
|
160
175
|
|
|
161
|
-
|
|
162
|
-
console.log(userNames);
|
|
163
|
-
```
|
|
176
|
+
These functions will throw an error at runtime if the query returns more than one column.
|
|
164
177
|
|
|
165
178
|
### Transactions
|
|
166
179
|
|
package/dist/default-pool.d.ts
CHANGED
|
@@ -50,49 +50,6 @@ export declare const endTransactionAsync: (client: import("pg").PoolClient, err:
|
|
|
50
50
|
* will be committed otherwise.
|
|
51
51
|
*/
|
|
52
52
|
export declare const runInTransactionAsync: <T>(fn: (client: import("pg").PoolClient) => Promise<T>) => Promise<T>;
|
|
53
|
-
/**
|
|
54
|
-
* Executes a query with the specified parameters.
|
|
55
|
-
*
|
|
56
|
-
* @deprecated Use {@link execute} instead.
|
|
57
|
-
*
|
|
58
|
-
* Using the return value of this function directly is not recommended. Instead, use
|
|
59
|
-
* {@link queryRows}, {@link queryRow}, or {@link queryOptionalRow}.
|
|
60
|
-
*/
|
|
61
|
-
export declare const queryAsync: (sql: string, params: QueryParams) => Promise<import("pg").QueryResult<any>>;
|
|
62
|
-
/**
|
|
63
|
-
* Executes a query with the specified parameters. Errors if the query does
|
|
64
|
-
* not return exactly one row.
|
|
65
|
-
*
|
|
66
|
-
* @deprecated Use {@link executeRow} or {@link queryRow} instead.
|
|
67
|
-
*/
|
|
68
|
-
export declare const queryOneRowAsync: (sql: string, params: QueryParams) => Promise<import("pg").default.QueryResult<any>>;
|
|
69
|
-
/**
|
|
70
|
-
* Executes a query with the specified parameters. Errors if the query
|
|
71
|
-
* returns more than one row.
|
|
72
|
-
*
|
|
73
|
-
* @deprecated Use {@link queryOptionalRow} instead.
|
|
74
|
-
*/
|
|
75
|
-
export declare const queryZeroOrOneRowAsync: (sql: string, params: QueryParams) => Promise<import("pg").default.QueryResult<any>>;
|
|
76
|
-
/**
|
|
77
|
-
* Calls the given sproc with the specified parameters.
|
|
78
|
-
*
|
|
79
|
-
* @deprecated Use {@link callRows} instead.
|
|
80
|
-
*/
|
|
81
|
-
export declare const callAsync: (functionName: string, params: any[]) => Promise<import("pg").default.QueryResult<any>>;
|
|
82
|
-
/**
|
|
83
|
-
* Calls the given sproc with the specified parameters. Errors if the
|
|
84
|
-
* sproc does not return exactly one row.
|
|
85
|
-
*
|
|
86
|
-
* @deprecated Use {@link callRow} instead.
|
|
87
|
-
*/
|
|
88
|
-
export declare const callOneRowAsync: (functionName: string, params: any[]) => Promise<import("pg").default.QueryResult<any>>;
|
|
89
|
-
/**
|
|
90
|
-
* Calls the given sproc with the specified parameters. Errors if the
|
|
91
|
-
* sproc returns more than one row.
|
|
92
|
-
*
|
|
93
|
-
* @deprecated Use {@link callOptionalRow} instead.
|
|
94
|
-
*/
|
|
95
|
-
export declare const callZeroOrOneRowAsync: (functionName: string, params: any[]) => Promise<import("pg").default.QueryResult<any>>;
|
|
96
53
|
/**
|
|
97
54
|
* Calls a sproc with the specified parameters using a specific client.
|
|
98
55
|
*/
|
|
@@ -110,53 +67,99 @@ export declare const callWithClientZeroOrOneRowAsync: (client: import("pg").Pool
|
|
|
110
67
|
/**
|
|
111
68
|
* Executes a query with the specified parameters. Returns an array of rows
|
|
112
69
|
* that conform to the given Zod schema.
|
|
113
|
-
*
|
|
114
|
-
* If the query returns a single column, the return value will be a list of column values.
|
|
115
70
|
*/
|
|
116
71
|
export declare const queryRows: {
|
|
117
|
-
<Model extends import("
|
|
118
|
-
<Model extends import("
|
|
72
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
73
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
119
74
|
};
|
|
120
75
|
/**
|
|
121
76
|
* Executes a query with the specified parameters. Returns exactly one row that conforms to the given Zod schema.
|
|
122
|
-
*
|
|
123
|
-
* If the query returns a single column, the return value will be the column value itself.
|
|
124
77
|
*/
|
|
125
78
|
export declare const queryRow: {
|
|
126
|
-
<Model extends import("
|
|
127
|
-
<Model extends import("
|
|
79
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
80
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
128
81
|
};
|
|
129
82
|
/**
|
|
130
83
|
* Executes a query with the specified parameters. Returns either null or a
|
|
131
84
|
* single row that conforms to the given Zod schema, and errors otherwise.
|
|
132
|
-
*
|
|
133
|
-
* If the query returns a single column, the return value will be the column value itself.
|
|
134
85
|
*/
|
|
135
86
|
export declare const queryOptionalRow: {
|
|
136
|
-
<Model extends import("
|
|
137
|
-
<Model extends import("
|
|
87
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
88
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
138
89
|
};
|
|
139
90
|
/**
|
|
140
91
|
* Calls the given sproc with the specified parameters.
|
|
141
92
|
* Errors if the sproc does not return anything.
|
|
142
93
|
*/
|
|
143
94
|
export declare const callRows: {
|
|
144
|
-
<Model extends import("
|
|
145
|
-
<Model extends import("
|
|
95
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
96
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
146
97
|
};
|
|
147
98
|
/**
|
|
148
99
|
* Calls the given sproc with the specified parameters.
|
|
149
100
|
* Returns exactly one row from the sproc that conforms to the given Zod schema.
|
|
150
101
|
*/
|
|
151
102
|
export declare const callRow: {
|
|
152
|
-
<Model extends import("
|
|
153
|
-
<Model extends import("
|
|
103
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
104
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
154
105
|
};
|
|
155
106
|
/**
|
|
156
107
|
* Calls the given sproc with the specified parameters. Returns either null
|
|
157
108
|
* or a single row that conforms to the given Zod schema.
|
|
158
109
|
*/
|
|
159
110
|
export declare const callOptionalRow: {
|
|
111
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
112
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Executes a query and returns all values from a single column, validated
|
|
116
|
+
* against the given Zod schema. Errors if the query returns more than one column.
|
|
117
|
+
*/
|
|
118
|
+
export declare const queryScalars: {
|
|
119
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
120
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Executes a query and returns a single value from a single column, validated
|
|
124
|
+
* against the given Zod schema. Errors if the query does not return exactly
|
|
125
|
+
* one row or returns more than one column.
|
|
126
|
+
*/
|
|
127
|
+
export declare const queryScalar: {
|
|
128
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
129
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Executes a query and returns a single value from a single column, or null
|
|
133
|
+
* if no rows are returned. Validated against the given Zod schema. Errors if
|
|
134
|
+
* the query returns more than one row or more than one column.
|
|
135
|
+
*/
|
|
136
|
+
export declare const queryOptionalScalar: {
|
|
137
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
138
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, params: QueryParams, model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Calls the given sproc and returns all values from a single column, validated
|
|
142
|
+
* against the given Zod schema. Errors if the sproc returns more than one column.
|
|
143
|
+
*/
|
|
144
|
+
export declare const callScalars: {
|
|
145
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
146
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model>[]>;
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
149
|
+
* Calls the given sproc and returns a single value from a single column, validated
|
|
150
|
+
* against the given Zod schema. Errors if the sproc does not return exactly
|
|
151
|
+
* one row or returns more than one column.
|
|
152
|
+
*/
|
|
153
|
+
export declare const callScalar: {
|
|
154
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
155
|
+
<Model extends import("zod").ZodTypeAny>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model>>;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* Calls the given sproc and returns a single value from a single column, or
|
|
159
|
+
* null if no rows are returned. Validated against the given Zod schema.
|
|
160
|
+
* Errors if the sproc returns more than one row or more than one column.
|
|
161
|
+
*/
|
|
162
|
+
export declare const callOptionalScalar: {
|
|
160
163
|
<Model extends import("zod").ZodTypeAny>(sql: string, model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
161
164
|
<Model extends import("zod").ZodTypeAny>(sql: string, params: any[], model: Model): Promise<import("zod").TypeOf<Model> | null>;
|
|
162
165
|
};
|
|
@@ -174,8 +177,8 @@ export declare const executeRow: (sql: string, params?: QueryParams) => Promise<
|
|
|
174
177
|
* Each row will be parsed by the given Zod schema.
|
|
175
178
|
*/
|
|
176
179
|
export declare const queryCursor: {
|
|
177
|
-
<Model extends import("
|
|
178
|
-
<Model extends import("
|
|
180
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, model: Model): Promise<CursorIterator<import("zod").TypeOf<Model>>>;
|
|
181
|
+
<Model extends import("./pool.js").AnyRowSchema>(sql: string, params: QueryParams, model: Model): Promise<CursorIterator<import("zod").TypeOf<Model>>>;
|
|
179
182
|
};
|
|
180
183
|
/**
|
|
181
184
|
* Set the schema to use for the search path.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-pool.d.ts","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAEhF,QAAA,MAAM,WAAW,cAAqB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,CAAC;AAe9D;;GAEG;AACH,eAAO,MAAM,SAAS,gJAA0C,CAAC;AACjE;;GAEG;AACH,eAAO,MAAM,UAAU,qBAA2C,CAAC;AACnE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,wCAA+C,CAAC;AAE3E;;GAEG;AACH,eAAO,MAAM,oBAAoB,uHAAqD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,uHAA2D,CAAC;AAEnG;;;GAGG;A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C;AACrE;;;;GAIG;AACH,eAAO,MAAM,eAAe,0CAAgD,CAAC;AAC7E;;;;GAIG;AACH,eAAO,MAAM,eAAe,qBAAgD,CAAC;AAC7E;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,qCAA2D,CAAC;AAEnG;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,mCAAyD,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 * @deprecated Use {@link execute} instead.\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 executeRow} or {@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/**\n * Executes a query with the specified parameters. Returns the number of rows affected.\n */\nexport const execute = defaultPool.execute.bind(defaultPool);\n\n/**\n * Executes a query with the specified parameter, and errors if the query doesn't return exactly one row.\n */\nexport const executeRow = defaultPool.executeRow.bind(defaultPool);\n\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 * @returns 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\n/**\n * Deletes all schemas starting with the given prefix.\n *\n * @param prefix The prefix of the schemas to delete.\n */\nexport const clearSchemasStartingWith = defaultPool.clearSchemasStartingWith.bind(defaultPool);\n"]}
|
|
1
|
+
{"version":3,"file":"default-pool.d.ts","sourceRoot":"","sources":["../src/default-pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,YAAY,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAEhF,QAAA,MAAM,WAAW,cAAqB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,CAAC;AAe9D;;GAEG;AACH,eAAO,MAAM,SAAS,gJAA0C,CAAC;AACjE;;GAEG;AACH,eAAO,MAAM,UAAU,qBAA2C,CAAC;AACnE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,wCAA+C,CAAC;AAE3E;;GAEG;AACH,eAAO,MAAM,oBAAoB,uHAAqD,CAAC;AAEvF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,uHAA2D,CAAC;AAEnG;;;GAGG;AACH,eAAO,MAAM,gCAAgC,+GACmB,CAAC;AACjE;;GAEG;AACH,eAAO,MAAM,uBAAuB,oDAAwD,CAAC;AAC7F,eAAO,MAAM,qBAAqB,wCAAsD,CAA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BAA0B,qCAA2D,CAAC;AAEnG;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,mCAAyD,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 * 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 */\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 */\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 */\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 * Executes a query and returns all values from a single column, validated\n * against the given Zod schema. Errors if the query returns more than one column.\n */\nexport const queryScalars = defaultPool.queryScalars.bind(defaultPool);\n/**\n * Executes a query and returns a single value from a single column, validated\n * against the given Zod schema. Errors if the query does not return exactly\n * one row or returns more than one column.\n */\nexport const queryScalar = defaultPool.queryScalar.bind(defaultPool);\n/**\n * Executes a query and returns a single value from a single column, or null\n * if no rows are returned. Validated against the given Zod schema. Errors if\n * the query returns more than one row or more than one column.\n */\nexport const queryOptionalScalar = defaultPool.queryOptionalScalar.bind(defaultPool);\n/**\n * Calls the given sproc and returns all values from a single column, validated\n * against the given Zod schema. Errors if the sproc returns more than one column.\n */\nexport const callScalars = defaultPool.callScalars.bind(defaultPool);\n/**\n * Calls the given sproc and returns a single value from a single column, validated\n * against the given Zod schema. Errors if the sproc does not return exactly\n * one row or returns more than one column.\n */\nexport const callScalar = defaultPool.callScalar.bind(defaultPool);\n/**\n * Calls the given sproc and returns a single value from a single column, or\n * null if no rows are returned. Validated against the given Zod schema.\n * Errors if the sproc returns more than one row or more than one column.\n */\nexport const callOptionalScalar = defaultPool.callOptionalScalar.bind(defaultPool);\n\n/**\n * Executes a query with the specified parameters. Returns the number of rows affected.\n */\nexport const execute = defaultPool.execute.bind(defaultPool);\n\n/**\n * Executes a query with the specified parameter, and errors if the query doesn't return exactly one row.\n */\nexport const executeRow = defaultPool.executeRow.bind(defaultPool);\n\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 * @returns 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\n/**\n * Deletes all schemas starting with the given prefix.\n *\n * @param prefix The prefix of the schemas to delete.\n */\nexport const clearSchemasStartingWith = defaultPool.clearSchemasStartingWith.bind(defaultPool);\n"]}
|
package/dist/default-pool.js
CHANGED
|
@@ -61,49 +61,6 @@ export const endTransactionAsync = defaultPool.endTransactionAsync.bind(defaultP
|
|
|
61
61
|
* will be committed otherwise.
|
|
62
62
|
*/
|
|
63
63
|
export const runInTransactionAsync = defaultPool.runInTransactionAsync.bind(defaultPool);
|
|
64
|
-
/**
|
|
65
|
-
* Executes a query with the specified parameters.
|
|
66
|
-
*
|
|
67
|
-
* @deprecated Use {@link execute} instead.
|
|
68
|
-
*
|
|
69
|
-
* Using the return value of this function directly is not recommended. Instead, use
|
|
70
|
-
* {@link queryRows}, {@link queryRow}, or {@link queryOptionalRow}.
|
|
71
|
-
*/
|
|
72
|
-
export const queryAsync = defaultPool.queryAsync.bind(defaultPool);
|
|
73
|
-
/**
|
|
74
|
-
* Executes a query with the specified parameters. Errors if the query does
|
|
75
|
-
* not return exactly one row.
|
|
76
|
-
*
|
|
77
|
-
* @deprecated Use {@link executeRow} or {@link queryRow} instead.
|
|
78
|
-
*/
|
|
79
|
-
export const queryOneRowAsync = defaultPool.queryOneRowAsync.bind(defaultPool);
|
|
80
|
-
/**
|
|
81
|
-
* Executes a query with the specified parameters. Errors if the query
|
|
82
|
-
* returns more than one row.
|
|
83
|
-
*
|
|
84
|
-
* @deprecated Use {@link queryOptionalRow} instead.
|
|
85
|
-
*/
|
|
86
|
-
export const queryZeroOrOneRowAsync = defaultPool.queryZeroOrOneRowAsync.bind(defaultPool);
|
|
87
|
-
/**
|
|
88
|
-
* Calls the given sproc with the specified parameters.
|
|
89
|
-
*
|
|
90
|
-
* @deprecated Use {@link callRows} instead.
|
|
91
|
-
*/
|
|
92
|
-
export const callAsync = defaultPool.callAsync.bind(defaultPool);
|
|
93
|
-
/**
|
|
94
|
-
* Calls the given sproc with the specified parameters. Errors if the
|
|
95
|
-
* sproc does not return exactly one row.
|
|
96
|
-
*
|
|
97
|
-
* @deprecated Use {@link callRow} instead.
|
|
98
|
-
*/
|
|
99
|
-
export const callOneRowAsync = defaultPool.callOneRowAsync.bind(defaultPool);
|
|
100
|
-
/**
|
|
101
|
-
* Calls the given sproc with the specified parameters. Errors if the
|
|
102
|
-
* sproc returns more than one row.
|
|
103
|
-
*
|
|
104
|
-
* @deprecated Use {@link callOptionalRow} instead.
|
|
105
|
-
*/
|
|
106
|
-
export const callZeroOrOneRowAsync = defaultPool.callZeroOrOneRowAsync.bind(defaultPool);
|
|
107
64
|
/**
|
|
108
65
|
* Calls a sproc with the specified parameters using a specific client.
|
|
109
66
|
*/
|
|
@@ -121,21 +78,15 @@ export const callWithClientZeroOrOneRowAsync = defaultPool.callWithClientZeroOrO
|
|
|
121
78
|
/**
|
|
122
79
|
* Executes a query with the specified parameters. Returns an array of rows
|
|
123
80
|
* that conform to the given Zod schema.
|
|
124
|
-
*
|
|
125
|
-
* If the query returns a single column, the return value will be a list of column values.
|
|
126
81
|
*/
|
|
127
82
|
export const queryRows = defaultPool.queryRows.bind(defaultPool);
|
|
128
83
|
/**
|
|
129
84
|
* Executes a query with the specified parameters. Returns exactly one row that conforms to the given Zod schema.
|
|
130
|
-
*
|
|
131
|
-
* If the query returns a single column, the return value will be the column value itself.
|
|
132
85
|
*/
|
|
133
86
|
export const queryRow = defaultPool.queryRow.bind(defaultPool);
|
|
134
87
|
/**
|
|
135
88
|
* Executes a query with the specified parameters. Returns either null or a
|
|
136
89
|
* single row that conforms to the given Zod schema, and errors otherwise.
|
|
137
|
-
*
|
|
138
|
-
* If the query returns a single column, the return value will be the column value itself.
|
|
139
90
|
*/
|
|
140
91
|
export const queryOptionalRow = defaultPool.queryOptionalRow.bind(defaultPool);
|
|
141
92
|
/**
|
|
@@ -153,6 +104,40 @@ export const callRow = defaultPool.callRow.bind(defaultPool);
|
|
|
153
104
|
* or a single row that conforms to the given Zod schema.
|
|
154
105
|
*/
|
|
155
106
|
export const callOptionalRow = defaultPool.callOptionalRow.bind(defaultPool);
|
|
107
|
+
/**
|
|
108
|
+
* Executes a query and returns all values from a single column, validated
|
|
109
|
+
* against the given Zod schema. Errors if the query returns more than one column.
|
|
110
|
+
*/
|
|
111
|
+
export const queryScalars = defaultPool.queryScalars.bind(defaultPool);
|
|
112
|
+
/**
|
|
113
|
+
* Executes a query and returns a single value from a single column, validated
|
|
114
|
+
* against the given Zod schema. Errors if the query does not return exactly
|
|
115
|
+
* one row or returns more than one column.
|
|
116
|
+
*/
|
|
117
|
+
export const queryScalar = defaultPool.queryScalar.bind(defaultPool);
|
|
118
|
+
/**
|
|
119
|
+
* Executes a query and returns a single value from a single column, or null
|
|
120
|
+
* if no rows are returned. Validated against the given Zod schema. Errors if
|
|
121
|
+
* the query returns more than one row or more than one column.
|
|
122
|
+
*/
|
|
123
|
+
export const queryOptionalScalar = defaultPool.queryOptionalScalar.bind(defaultPool);
|
|
124
|
+
/**
|
|
125
|
+
* Calls the given sproc and returns all values from a single column, validated
|
|
126
|
+
* against the given Zod schema. Errors if the sproc returns more than one column.
|
|
127
|
+
*/
|
|
128
|
+
export const callScalars = defaultPool.callScalars.bind(defaultPool);
|
|
129
|
+
/**
|
|
130
|
+
* Calls the given sproc and returns a single value from a single column, validated
|
|
131
|
+
* against the given Zod schema. Errors if the sproc does not return exactly
|
|
132
|
+
* one row or returns more than one column.
|
|
133
|
+
*/
|
|
134
|
+
export const callScalar = defaultPool.callScalar.bind(defaultPool);
|
|
135
|
+
/**
|
|
136
|
+
* Calls the given sproc and returns a single value from a single column, or
|
|
137
|
+
* null if no rows are returned. Validated against the given Zod schema.
|
|
138
|
+
* Errors if the sproc returns more than one row or more than one column.
|
|
139
|
+
*/
|
|
140
|
+
export const callOptionalScalar = defaultPool.callOptionalScalar.bind(defaultPool);
|
|
156
141
|
/**
|
|
157
142
|
* Executes a query with the specified parameters. Returns the number of rows affected.
|
|
158
143
|
*/
|
package/dist/default-pool.js.map
CHANGED
|
@@ -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;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,CAAC,CAAC;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C7E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CAAC,0BAA0B,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CAAC,wBAAwB,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 * @deprecated Use {@link execute} instead.\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 executeRow} or {@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/**\n * Executes a query with the specified parameters. Returns the number of rows affected.\n */\nexport const execute = defaultPool.execute.bind(defaultPool);\n\n/**\n * Executes a query with the specified parameter, and errors if the query doesn't return exactly one row.\n */\nexport const executeRow = defaultPool.executeRow.bind(defaultPool);\n\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 * @returns 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\n/**\n * Deletes all schemas starting with the given prefix.\n *\n * @param prefix The prefix of the schemas to delete.\n */\nexport const clearSchemasStartingWith = defaultPool.clearSchemasStartingWith.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;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G;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAEnE;;;;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;AAEnG;;;;GAIG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,WAAW,CAAC,wBAAwB,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 * 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 */\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 */\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 */\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 * Executes a query and returns all values from a single column, validated\n * against the given Zod schema. Errors if the query returns more than one column.\n */\nexport const queryScalars = defaultPool.queryScalars.bind(defaultPool);\n/**\n * Executes a query and returns a single value from a single column, validated\n * against the given Zod schema. Errors if the query does not return exactly\n * one row or returns more than one column.\n */\nexport const queryScalar = defaultPool.queryScalar.bind(defaultPool);\n/**\n * Executes a query and returns a single value from a single column, or null\n * if no rows are returned. Validated against the given Zod schema. Errors if\n * the query returns more than one row or more than one column.\n */\nexport const queryOptionalScalar = defaultPool.queryOptionalScalar.bind(defaultPool);\n/**\n * Calls the given sproc and returns all values from a single column, validated\n * against the given Zod schema. Errors if the sproc returns more than one column.\n */\nexport const callScalars = defaultPool.callScalars.bind(defaultPool);\n/**\n * Calls the given sproc and returns a single value from a single column, validated\n * against the given Zod schema. Errors if the sproc does not return exactly\n * one row or returns more than one column.\n */\nexport const callScalar = defaultPool.callScalar.bind(defaultPool);\n/**\n * Calls the given sproc and returns a single value from a single column, or\n * null if no rows are returned. Validated against the given Zod schema.\n * Errors if the sproc returns more than one row or more than one column.\n */\nexport const callOptionalScalar = defaultPool.callOptionalScalar.bind(defaultPool);\n\n/**\n * Executes a query with the specified parameters. Returns the number of rows affected.\n */\nexport const execute = defaultPool.execute.bind(defaultPool);\n\n/**\n * Executes a query with the specified parameter, and errors if the query doesn't return exactly one row.\n */\nexport const executeRow = defaultPool.executeRow.bind(defaultPool);\n\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 * @returns 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\n/**\n * Deletes all schemas starting with the given prefix.\n *\n * @param prefix The prefix of the schemas to delete.\n */\nexport const clearSchemasStartingWith = defaultPool.clearSchemasStartingWith.bind(defaultPool);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-pool.test.d.ts","sourceRoot":"","sources":["../src/default-pool.test.ts"],"names":[],"mappings":"","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"]}
|
|
1
|
+
{"version":3,"file":"default-pool.test.d.ts","sourceRoot":"","sources":["../src/default-pool.test.ts"],"names":[],"mappings":"","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 // Deprecated methods not re-exported from the default pool\n 'queryAsync',\n 'queryOneRowAsync',\n 'queryZeroOrOneRowAsync',\n 'callAsync',\n 'callOneRowAsync',\n 'callZeroOrOneRowAsync',\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"]}
|
|
@@ -20,6 +20,13 @@ const HIDDEN_PROPERTIES = new Set([
|
|
|
20
20
|
'idleCount',
|
|
21
21
|
'waitingCount',
|
|
22
22
|
'queryCount',
|
|
23
|
+
// Deprecated methods not re-exported from the default pool
|
|
24
|
+
'queryAsync',
|
|
25
|
+
'queryOneRowAsync',
|
|
26
|
+
'queryZeroOrOneRowAsync',
|
|
27
|
+
'callAsync',
|
|
28
|
+
'callOneRowAsync',
|
|
29
|
+
'callZeroOrOneRowAsync',
|
|
23
30
|
]);
|
|
24
31
|
describe('sqldb', () => {
|
|
25
32
|
it('exports the full PostgresPool interface', () => {
|
|
@@ -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,uBAAuB;IACvB,qBAAqB;IACrB,yBAAyB;IACzB,UAAU;IACV,YAAY;IACZ,WAAW;IACX,cAAc;IACd,YAAY;
|
|
1
|
+
{"version":3,"file":"default-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;aACxC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACjB,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,EAAE,CAAE,MAAc,CAAC,IAAI,CAAC,CAAC,CAAC;QAAA,CAClC,CAAC,CAAC;IAAA,CACN,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC;QAC3C,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,CAAC;YACjD,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;QAAA,CACvC,CAAC,CAAC;IAAA,CACJ,CAAC,CAAC;AAAA,CACJ,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 // Deprecated methods not re-exported from the default pool\n 'queryAsync',\n 'queryOneRowAsync',\n 'queryZeroOrOneRowAsync',\n 'callAsync',\n 'callOneRowAsync',\n 'callZeroOrOneRowAsync',\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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { type PoolClient } from 'pg';
|
|
2
2
|
export { loadSql, loadSqlEquiv } from './loader.js';
|
|
3
|
-
export { PostgresPool, type PostgresPoolConfig } from './pool.js';
|
|
3
|
+
export { type AnyRowSchema, PostgresPool, type PostgresPoolConfig } from './pool.js';
|
|
4
4
|
export * from './default-pool.js';
|
|
5
5
|
export { formatQueryWithErrorPosition } from './error.js';
|
|
6
6
|
export { makePostgresTestUtils, type PostgresTestUtils, type PostgresTestUtilsOptions, } from './test-utils.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,IAAI,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,KAAK,YAAY,EAAE,YAAY,EAAE,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAErF,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EACL,qBAAqB,EACrB,KAAK,iBAAiB,EACtB,KAAK,wBAAwB,GAC9B,MAAM,iBAAiB,CAAC","sourcesContent":["export { type PoolClient } from 'pg';\n\nexport { loadSql, loadSqlEquiv } from './loader.js';\nexport { type AnyRowSchema, PostgresPool, type PostgresPoolConfig } from './pool.js';\n\nexport * from './default-pool.js';\n\nexport { formatQueryWithErrorPosition } from './error.js';\n\nexport {\n makePostgresTestUtils,\n type PostgresTestUtils,\n type PostgresTestUtilsOptions,\n} from './test-utils.js';\n"]}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,IAAI,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,IAAI,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAqB,YAAY,EAA2B,MAAM,WAAW,CAAC;AAErF,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAE1D,OAAO,EACL,qBAAqB,GAGtB,MAAM,iBAAiB,CAAC","sourcesContent":["export { type PoolClient } from 'pg';\n\nexport { loadSql, loadSqlEquiv } from './loader.js';\nexport { type AnyRowSchema, PostgresPool, type PostgresPoolConfig } from './pool.js';\n\nexport * from './default-pool.js';\n\nexport { formatQueryWithErrorPosition } from './error.js';\n\nexport {\n makePostgresTestUtils,\n type PostgresTestUtils,\n type PostgresTestUtilsOptions,\n} from './test-utils.js';\n"]}
|