11import { FastifyInstance } from 'fastify'
2- import { PostgresMeta } from '../../lib'
3- import { DEFAULT_POOL_CONFIG } from '../constants'
2+ import PgMetaCache from '../pgMetaCache'
43
54export default async ( fastify : FastifyInstance ) => {
65 fastify . get < {
@@ -14,9 +13,8 @@ export default async (fastify: FastifyInstance) => {
1413 const limit = request . query . limit
1514 const offset = request . query . offset
1615
17- const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
16+ const pgMeta = PgMetaCache . get ( connectionString )
1817 const { data, error } = await pgMeta . extensions . list ( { limit, offset } )
19- await pgMeta . end ( )
2018 if ( error ) {
2119 request . log . error ( JSON . stringify ( { error, req : request . body } ) )
2220 reply . code ( 500 )
@@ -34,9 +32,8 @@ export default async (fastify: FastifyInstance) => {
3432 } > ( '/:name' , async ( request , reply ) => {
3533 const connectionString = request . headers . pg
3634
37- const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
35+ const pgMeta = PgMetaCache . get ( connectionString )
3836 const { data, error } = await pgMeta . extensions . retrieve ( { name : request . params . name } )
39- await pgMeta . end ( )
4037 if ( error ) {
4138 request . log . error ( JSON . stringify ( { error, req : request . body } ) )
4239 reply . code ( 404 )
@@ -52,9 +49,8 @@ export default async (fastify: FastifyInstance) => {
5249 } > ( '/' , async ( request , reply ) => {
5350 const connectionString = request . headers . pg
5451
55- const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
52+ const pgMeta = PgMetaCache . get ( connectionString )
5653 const { data, error } = await pgMeta . extensions . create ( request . body )
57- await pgMeta . end ( )
5854 if ( error ) {
5955 request . log . error ( JSON . stringify ( { error, req : request . body } ) )
6056 reply . code ( 400 )
@@ -73,9 +69,8 @@ export default async (fastify: FastifyInstance) => {
7369 } > ( '/:name' , async ( request , reply ) => {
7470 const connectionString = request . headers . pg
7571
76- const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
72+ const pgMeta = PgMetaCache . get ( connectionString )
7773 const { data, error } = await pgMeta . extensions . update ( request . params . name , request . body )
78- await pgMeta . end ( )
7974 if ( error ) {
8075 request . log . error ( JSON . stringify ( { error, req : request . body } ) )
8176 reply . code ( 400 )
@@ -98,9 +93,8 @@ export default async (fastify: FastifyInstance) => {
9893 const connectionString = request . headers . pg
9994 const cascade = request . query . cascade === 'true'
10095
101- const pgMeta = new PostgresMeta ( { ... DEFAULT_POOL_CONFIG , connectionString } )
96+ const pgMeta = PgMetaCache . get ( connectionString )
10297 const { data, error } = await pgMeta . extensions . remove ( request . params . name , { cascade } )
103- await pgMeta . end ( )
10498 if ( error ) {
10599 request . log . error ( JSON . stringify ( { error, req : request . body } ) )
106100 reply . code ( 400 )
0 commit comments