Skip to content

Commit ad320bc

Browse files
committed
fix: disable slonik query validation and parsing layer
1 parent 721d455 commit ad320bc

1 file changed

Lines changed: 2 additions & 35 deletions

File tree

database/index.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import { DatabasePool, createTypeParserPreset } from 'slonik';
22
import {
33
createPool,
4-
type Interceptor,
5-
type QueryResultRow,
6-
SchemaValidationError,
74
} from 'slonik';
85

96
const DB_URL = process.env.DB_URL || 'postgres://postgres:postgres@db:5432/postgres';
107
const CA_CERT = process.env.CA_CERT
118
let pool: DatabasePool;
129

1310
const baseConfig = {
14-
interceptors: [createResultParserInterceptor()],
15-
typeParsers:[...createTypeParserPreset()]
11+
typeParsers:[]
1612
}
1713

1814
const envConfigs: {[env:string]:{}} = {
@@ -25,6 +21,7 @@ const envConfigs: {[env:string]:{}} = {
2521
};
2622

2723
const dbConfig = {...baseConfig, ...envConfigs[process.env.NODE_ENV || 'development']};
24+
2825
export async function getPool(){
2926
if (pool) return pool;
3027

@@ -38,33 +35,3 @@ export async function getPool(){
3835

3936
return pool;
4037
}
41-
42-
function createResultParserInterceptor(): Interceptor {
43-
return {
44-
// If you are not going to transform results using Zod, then you should use `afterQueryExecution` instead.
45-
// Future versions of Zod will provide a more efficient parser when parsing without transformations.
46-
// You can even combine the two – use `afterQueryExecution` to validate results, and (conditionally)
47-
// transform results as needed in `transformRow`.
48-
transformRow: async (executionContext, actualQuery, row) => {
49-
const { log, resultParser } = executionContext;
50-
51-
if (!resultParser) {
52-
return row;
53-
}
54-
55-
// It is recommended (but not required) to parse async to avoid blocking the event loop during validation
56-
// const validationResult = await resultParser.safeParseAsync(row);
57-
//
58-
// if (!validationResult.success) {
59-
// throw new SchemaValidationError(
60-
// actualQuery,
61-
// row,
62-
// validationResult.error.issues
63-
// );
64-
// }
65-
//
66-
// return validationResult.data as QueryResultRow;
67-
return row;
68-
},
69-
};
70-
};

0 commit comments

Comments
 (0)