11import { FastifyInstance } from 'fastify'
2- import PgMetaCache from '../pgMetaCache.js'
2+ import { PostgresMeta } from '../../lib/index.js'
3+ import { DEFAULT_POOL_CONFIG } from '../constants.js'
34import { extractRequestForLogging } from '../utils.js'
45
56export default async ( fastify : FastifyInstance ) => {
@@ -21,14 +22,15 @@ export default async (fastify: FastifyInstance) => {
2122 const limit = request . query . limit
2223 const offset = request . query . offset
2324
24- const pgMeta = PgMetaCache . get ( connectionString )
25+ const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
2526 const { data, error } = await pgMeta . columns . list ( {
2627 includeSystemSchemas,
2728 includedSchemas,
2829 excludedSchemas,
2930 limit,
3031 offset,
3132 } )
33+ await pgMeta . end ( )
3234 if ( error ) {
3335 request . log . error ( { error, request : extractRequestForLogging ( request ) } )
3436 reply . code ( 500 )
@@ -58,13 +60,14 @@ export default async (fastify: FastifyInstance) => {
5860 } = request
5961 const includeSystemSchemas = request . query . include_system_schemas === 'true'
6062
61- const pgMeta = PgMetaCache . get ( connectionString )
63+ const pgMeta : PostgresMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
6264 const { data, error } = await pgMeta . columns . list ( {
6365 tableId : Number ( tableId ) ,
6466 includeSystemSchemas,
6567 limit : Number ( limit ) ,
6668 offset : Number ( offset ) ,
6769 } )
70+ await pgMeta . end ( )
6871 if ( error ) {
6972 request . log . error ( { error, request : extractRequestForLogging ( request ) } )
7073 reply . code ( 500 )
@@ -79,8 +82,9 @@ export default async (fastify: FastifyInstance) => {
7982 } = request
8083 const ordinalPosition = ordinalPositionWithDot . slice ( 1 )
8184
82- const pgMeta = PgMetaCache . get ( connectionString )
85+ const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
8386 const { data, error } = await pgMeta . columns . retrieve ( { id : `${ tableId } .${ ordinalPosition } ` } )
87+ await pgMeta . end ( )
8488 if ( error ) {
8589 request . log . error ( { error, request : extractRequestForLogging ( request ) } )
8690 reply . code ( 400 )
@@ -100,8 +104,9 @@ export default async (fastify: FastifyInstance) => {
100104 } > ( '/' , async ( request , reply ) => {
101105 const connectionString = request . headers . pg
102106
103- const pgMeta = PgMetaCache . get ( connectionString )
107+ const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
104108 const { data, error } = await pgMeta . columns . create ( request . body as any )
109+ await pgMeta . end ( )
105110 if ( error ) {
106111 request . log . error ( { error, request : extractRequestForLogging ( request ) } )
107112 reply . code ( 400 )
@@ -121,8 +126,9 @@ export default async (fastify: FastifyInstance) => {
121126 } > ( '/:id(\\d+\\.\\d+)' , async ( request , reply ) => {
122127 const connectionString = request . headers . pg
123128
124- const pgMeta = PgMetaCache . get ( connectionString )
129+ const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
125130 const { data, error } = await pgMeta . columns . update ( request . params . id , request . body as any )
131+ await pgMeta . end ( )
126132 if ( error ) {
127133 request . log . error ( { error, request : extractRequestForLogging ( request ) } )
128134 reply . code ( 400 )
@@ -145,8 +151,9 @@ export default async (fastify: FastifyInstance) => {
145151 const connectionString = request . headers . pg
146152 const cascade = request . query . cascade === 'true'
147153
148- const pgMeta = PgMetaCache . get ( connectionString )
154+ const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
149155 const { data, error } = await pgMeta . columns . remove ( request . params . id , { cascade } )
156+ await pgMeta . end ( )
150157 if ( error ) {
151158 request . log . error ( { error, request : extractRequestForLogging ( request ) } )
152159 reply . code ( 400 )
0 commit comments