@prairielearn/postgres 1.9.4 → 2.0.1
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/.mocharc.cjs +3 -0
- package/CHANGELOG.md +12 -0
- package/README.md +0 -4
- package/dist/default-pool.d.ts +2 -2
- package/dist/default-pool.js +61 -65
- package/dist/default-pool.js.map +1 -1
- package/dist/default-pool.test.js +11 -35
- package/dist/default-pool.test.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +4 -25
- package/dist/index.js.map +1 -1
- package/dist/loader.js +9 -17
- package/dist/loader.js.map +1 -1
- package/dist/pool.d.ts +1 -1
- package/dist/pool.js +51 -59
- package/dist/pool.js.map +1 -1
- package/dist/pool.test.js +64 -70
- package/dist/pool.test.js.map +1 -1
- package/dist/test-utils.js +6 -36
- package/dist/test-utils.js.map +1 -1
- package/package.json +12 -11
- package/src/default-pool.test.ts +4 -2
- package/src/default-pool.ts +1 -1
- package/src/index.ts +9 -5
- package/src/pool.test.ts +11 -11
- package/src/pool.ts +10 -9
- package/src/test-utils.ts +1 -1
package/src/pool.test.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import chai from 'chai';
|
|
2
|
-
import chaiAsPromised from 'chai-as-promised';
|
|
3
1
|
import { Writable } from 'node:stream';
|
|
4
2
|
import { pipeline } from 'node:stream/promises';
|
|
3
|
+
|
|
4
|
+
import { use as chaiUse, assert } from 'chai';
|
|
5
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
5
6
|
import { z, ZodError } from 'zod';
|
|
6
7
|
|
|
7
8
|
import {
|
|
@@ -14,11 +15,10 @@ import {
|
|
|
14
15
|
callOptionalRow,
|
|
15
16
|
queryCursor,
|
|
16
17
|
queryValidatedCursor,
|
|
17
|
-
} from './default-pool';
|
|
18
|
-
import { makePostgresTestUtils } from './test-utils';
|
|
18
|
+
} from './default-pool.js';
|
|
19
|
+
import { makePostgresTestUtils } from './test-utils.js';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
const { assert } = chai;
|
|
21
|
+
chaiUse(chaiAsPromised);
|
|
22
22
|
|
|
23
23
|
const postgresTestUtils = makePostgresTestUtils({
|
|
24
24
|
database: 'prairielearn_postgres',
|
|
@@ -278,11 +278,11 @@ describe('@prairielearn/postgres', function () {
|
|
|
278
278
|
const maybeError = await readAllRows().catch((err) => err);
|
|
279
279
|
assert.instanceOf(maybeError, Error);
|
|
280
280
|
assert.match(maybeError.message, /syntax error/);
|
|
281
|
-
assert.isDefined(maybeError.data);
|
|
282
|
-
assert.equal(maybeError.data.sql, 'NOT VALID SQL');
|
|
283
|
-
assert.deepEqual(maybeError.data.sqlParams, { foo: 'bar' });
|
|
284
|
-
assert.isDefined(maybeError.data.sqlError);
|
|
285
|
-
assert.equal(maybeError.data.sqlError.severity, 'ERROR');
|
|
281
|
+
assert.isDefined((maybeError as any).data);
|
|
282
|
+
assert.equal((maybeError as any).data.sql, 'NOT VALID SQL');
|
|
283
|
+
assert.deepEqual((maybeError as any).data.sqlParams, { foo: 'bar' });
|
|
284
|
+
assert.isDefined((maybeError as any).data.sqlError);
|
|
285
|
+
assert.equal((maybeError as any).data.sqlError.severity, 'ERROR');
|
|
286
286
|
});
|
|
287
287
|
});
|
|
288
288
|
|
package/src/pool.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { Readable, Transform } from 'node:stream';
|
|
3
|
+
import { callbackify } from 'node:util';
|
|
4
|
+
|
|
5
|
+
import debugfn from 'debug';
|
|
1
6
|
import _ from 'lodash';
|
|
7
|
+
import multipipe from 'multipipe';
|
|
2
8
|
import pg, { QueryResult } from 'pg';
|
|
3
9
|
import Cursor from 'pg-cursor';
|
|
4
|
-
import debugFactory from 'debug';
|
|
5
|
-
import { callbackify } from 'node:util';
|
|
6
|
-
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
10
|
import { z } from 'zod';
|
|
8
|
-
import { Readable, Transform } from 'node:stream';
|
|
9
|
-
import multipipe from 'multipipe';
|
|
10
11
|
|
|
11
12
|
export type QueryParams = Record<string, any> | any[];
|
|
12
13
|
|
|
@@ -15,7 +16,7 @@ export interface CursorIterator<T> {
|
|
|
15
16
|
stream: (batchSize: number) => NodeJS.ReadWriteStream;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
const debug =
|
|
19
|
+
const debug = debugfn('@prairielearn/postgres');
|
|
19
20
|
const lastQueryMap = new WeakMap<pg.PoolClient, string>();
|
|
20
21
|
const searchSchemaMap = new WeakMap<pg.PoolClient, string>();
|
|
21
22
|
|
|
@@ -87,9 +88,9 @@ function paramsToArray(
|
|
|
87
88
|
let paramsArray: any[] = [];
|
|
88
89
|
while ((result = re.exec(remainingSql)) !== null) {
|
|
89
90
|
const v = result[1];
|
|
90
|
-
if (!
|
|
91
|
-
if (!
|
|
92
|
-
if (
|
|
91
|
+
if (!(v in map)) {
|
|
92
|
+
if (!(v in params)) throw new Error(`Missing parameter: ${v}`);
|
|
93
|
+
if (Array.isArray(params[v])) {
|
|
93
94
|
map[v] =
|
|
94
95
|
'ARRAY[' +
|
|
95
96
|
_.map(_.range(nParams + 1, nParams + params[v].length + 1), function (n) {
|