11import { DatabasePool , createTypeParserPreset } from 'slonik' ;
22import {
33 createPool ,
4- type Interceptor ,
5- type QueryResultRow ,
6- SchemaValidationError ,
74} from 'slonik' ;
85
96const DB_URL = process . env . DB_URL || 'postgres://postgres:postgres@db:5432/postgres' ;
107const CA_CERT = process . env . CA_CERT
118let pool : DatabasePool ;
129
1310const baseConfig = {
14- interceptors : [ createResultParserInterceptor ( ) ] ,
15- typeParsers :[ ...createTypeParserPreset ( ) ]
11+ typeParsers :[ ]
1612}
1713
1814const envConfigs : { [ env :string ] :{ } } = {
@@ -25,6 +21,7 @@ const envConfigs: {[env:string]:{}} = {
2521} ;
2622
2723const dbConfig = { ...baseConfig , ...envConfigs [ process . env . NODE_ENV || 'development' ] } ;
24+
2825export 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