import { types , Pool , PoolConfig } from 'pg' ; import { PostgresMetaResult } from './types' ; types . setTypeParser ( 20 , parseInt ) ; export const init = ( config ) => { let pool = new Pool ( config ) ; return { async query ( sql ) { try { if ( ! pool ) { const pool = new Pool ( config ) ; const { rows } = await pool . query ( sql ) ; await pool . end ( ) ; return { data : rows , error : null } ; } const { rows } = await pool . query ( sql ) ; return { data : rows , error : null } ; } catch ( e ) { return { data : null , error : { message : e . message } } ; } } , async end ( ) { const _pool = pool ; pool = null ; if ( _pool ) await _pool . end ( ) ; } , } ; } ;