declapract-typescript-ehmpathy 0.37.0 → 0.37.2
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/dist/practices/persist-with-rds/best-practice/src/utils/database/getDatabaseConnection.ts +6 -3
- package/dist/practices/persist-with-rds/best-practice/src/utils/database/withDatabaseContext.ts +5 -5
- package/dist/practices/typescript/best-practice/tsconfig.json +1 -1
- package/package.json +1 -1
package/dist/practices/persist-with-rds/best-practice/src/utils/database/getDatabaseConnection.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import pg, { Client, QueryResult } from 'pg';
|
|
1
|
+
import pg, { Client, QueryResult, QueryResultRow } from 'pg';
|
|
2
2
|
|
|
3
3
|
import { getConfig } from '../config/getConfig';
|
|
4
4
|
|
|
@@ -7,7 +7,10 @@ pg.types.setTypeParser(20, (value) => parseInt(value, 10)); // cast bigints to n
|
|
|
7
7
|
pg.types.setTypeParser(1700, (value) => parseFloat(value)); // cast numerics to numbers; by default, pg returns numerics as strings
|
|
8
8
|
|
|
9
9
|
export interface DatabaseConnection {
|
|
10
|
-
query: (args: {
|
|
10
|
+
query: <Row extends QueryResultRow>(args: {
|
|
11
|
+
sql: string;
|
|
12
|
+
values?: any[];
|
|
13
|
+
}) => Promise<QueryResult<Row>>;
|
|
11
14
|
end: () => Promise<void>;
|
|
12
15
|
}
|
|
13
16
|
|
|
@@ -56,7 +59,7 @@ export const getDatabaseConnection = async (): Promise<DatabaseConnection> => {
|
|
|
56
59
|
dbConnection.query(args).catch((error) => {
|
|
57
60
|
throw new DatabaseQueryError({
|
|
58
61
|
sql: args.sql,
|
|
59
|
-
values: args.values
|
|
62
|
+
values: args.values,
|
|
60
63
|
caught: error,
|
|
61
64
|
});
|
|
62
65
|
}),
|
package/dist/practices/persist-with-rds/best-practice/src/utils/database/withDatabaseContext.ts
CHANGED
|
@@ -3,6 +3,10 @@ import {
|
|
|
3
3
|
getDatabaseConnection,
|
|
4
4
|
} from './getDatabaseConnection';
|
|
5
5
|
|
|
6
|
+
export interface DatabaseContext {
|
|
7
|
+
dbConnection: DatabaseConnection;
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
/**
|
|
7
11
|
* wraps the function to provide a managed database connection to it's context, if one was not already passed in
|
|
8
12
|
*
|
|
@@ -19,11 +23,7 @@ import {
|
|
|
19
23
|
* await findById({ id: 821 }); // note how we don't have to pass in the dbConnection
|
|
20
24
|
* ```
|
|
21
25
|
*/
|
|
22
|
-
export const withDatabaseContext = <
|
|
23
|
-
P1,
|
|
24
|
-
P2 extends { dbConnection: DatabaseConnection },
|
|
25
|
-
R,
|
|
26
|
-
>(
|
|
26
|
+
export const withDatabaseContext = <P1, P2 extends DatabaseContext, R>(
|
|
27
27
|
logic: (input: P1, context: P2) => R | Promise<R>,
|
|
28
28
|
) => {
|
|
29
29
|
return async (
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "declapract-typescript-ehmpathy",
|
|
3
3
|
"author": "ehmpathy",
|
|
4
4
|
"description": "declapract best practices declarations for typescript",
|
|
5
|
-
"version": "0.37.
|
|
5
|
+
"version": "0.37.2",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "src/index.js",
|
|
8
8
|
"repository": "ehmpathy/declapract-typescript-ehmpathy",
|