pqb 0.7.6 → 0.7.8
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 +12 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.esm.js +9 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/adapter.ts +9 -1
- package/src/db.test.ts +13 -0
- package/src/errors.ts +1 -2
- package/src/test-utils/test-utils.ts +2 -2
- package/src/test-utils/user.csv +0 -1
package/package.json
CHANGED
package/src/adapter.ts
CHANGED
|
@@ -41,8 +41,9 @@ for (const key in types.builtins) {
|
|
|
41
41
|
|
|
42
42
|
const returnArg = (arg: unknown) => arg;
|
|
43
43
|
|
|
44
|
-
export type AdapterOptions = Omit<PoolConfig, 'types'> & {
|
|
44
|
+
export type AdapterOptions = Omit<PoolConfig, 'types' | 'connectionString'> & {
|
|
45
45
|
types?: TypeParsers;
|
|
46
|
+
databaseURL?: string;
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
export class Adapter {
|
|
@@ -51,6 +52,13 @@ export class Adapter {
|
|
|
51
52
|
|
|
52
53
|
constructor({ types = defaultTypeParsers, ...config }: AdapterOptions) {
|
|
53
54
|
this.types = types;
|
|
55
|
+
if (config.databaseURL) {
|
|
56
|
+
(config as PoolConfig).connectionString = config.databaseURL;
|
|
57
|
+
const url = new URL(config.databaseURL);
|
|
58
|
+
if (url.searchParams.get('ssl') === 'true') {
|
|
59
|
+
config.ssl = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
54
62
|
this.pool = new Pool(config);
|
|
55
63
|
}
|
|
56
64
|
|
package/src/db.test.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
adapter,
|
|
3
3
|
assertType,
|
|
4
4
|
db,
|
|
5
|
+
dbOptions,
|
|
5
6
|
expectSql,
|
|
6
7
|
User,
|
|
7
8
|
userData,
|
|
@@ -153,4 +154,16 @@ describe('db', () => {
|
|
|
153
154
|
expect(logger.warn).not.toBeCalled();
|
|
154
155
|
});
|
|
155
156
|
});
|
|
157
|
+
|
|
158
|
+
it('should use ssl when ssl=true query parameter provided on a databaseUrl option', () => {
|
|
159
|
+
const db = createDb({
|
|
160
|
+
...dbOptions,
|
|
161
|
+
databaseURL: dbOptions.databaseURL + '?ssl=true',
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(
|
|
165
|
+
(db.adapter.pool as unknown as { options: Record<string, unknown> })
|
|
166
|
+
.options.ssl,
|
|
167
|
+
).toBe(true);
|
|
168
|
+
});
|
|
156
169
|
});
|
package/src/errors.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DatabaseError } from 'pg';
|
|
2
1
|
import { ColumnsShape } from './columnSchema';
|
|
3
2
|
|
|
4
3
|
export class PormError extends Error {}
|
|
@@ -34,7 +33,7 @@ export type QueryErrorName =
|
|
|
34
33
|
|
|
35
34
|
export class QueryError<
|
|
36
35
|
T extends { shape: ColumnsShape } = { shape: ColumnsShape },
|
|
37
|
-
> extends
|
|
36
|
+
> extends Error {
|
|
38
37
|
message!: string;
|
|
39
38
|
name!: QueryErrorName;
|
|
40
39
|
stack: string | undefined;
|
|
@@ -12,11 +12,11 @@ import { MaybeArray, toArray } from '../utils';
|
|
|
12
12
|
import { Adapter } from '../adapter';
|
|
13
13
|
|
|
14
14
|
export const dbOptions = {
|
|
15
|
-
|
|
15
|
+
databaseURL: process.env.DATABASE_URL,
|
|
16
16
|
columnTypes,
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export const dbClient = new Client(dbOptions);
|
|
19
|
+
export const dbClient = new Client({ connectionString: dbOptions.databaseURL });
|
|
20
20
|
|
|
21
21
|
export const adapter = new Adapter(dbOptions);
|
|
22
22
|
|
package/src/test-utils/user.csv
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
1,name,password,,,,,,,,
|