1
- import { FastifyInstance } from 'fastify'
2
1
import { PostgresMeta } from '../../lib/index.js'
3
2
import { DEFAULT_POOL_CONFIG } from '../constants.js'
4
3
import { extractRequestForLogging } from '../utils.js'
@@ -59,38 +58,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
59
58
return data
60
59
}
61
60
)
62
- fastify . post (
63
- '/' ,
64
- {
65
- schema : {
66
- headers : Type . Object ( {
67
- pg : Type . String ( ) ,
68
- } ) ,
69
- body : postgresColumnCreateSchema ,
70
- response : {
71
- 200 : postgresColumnSchema ,
72
- 400 : Type . Object ( {
73
- error : Type . String ( ) ,
74
- } ) ,
75
- } ,
76
- } ,
77
- } ,
78
- async ( request , reply ) => {
79
- const connectionString = request . headers . pg
80
-
81
- const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
82
- const { data, error } = await pgMeta . columns . create ( request . body as any )
83
- await pgMeta . end ( )
84
- if ( error ) {
85
- request . log . error ( { error, request : extractRequestForLogging ( request ) } )
86
- reply . code ( 400 )
87
- if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
88
- return { error : error . message }
89
- }
90
61
91
- return data
92
- }
93
- )
94
62
fastify . get (
95
63
'/:tableId(^\\d+):ordinalPosition' ,
96
64
{
@@ -164,6 +132,40 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
164
132
}
165
133
}
166
134
)
135
+
136
+ fastify . post (
137
+ '/' ,
138
+ {
139
+ schema : {
140
+ headers : Type . Object ( {
141
+ pg : Type . String ( ) ,
142
+ } ) ,
143
+ body : postgresColumnCreateSchema ,
144
+ response : {
145
+ 200 : postgresColumnSchema ,
146
+ 400 : Type . Object ( {
147
+ error : Type . String ( ) ,
148
+ } ) ,
149
+ } ,
150
+ } ,
151
+ } ,
152
+ async ( request , reply ) => {
153
+ const connectionString = request . headers . pg
154
+
155
+ const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
156
+ const { data, error } = await pgMeta . columns . create ( request . body )
157
+ await pgMeta . end ( )
158
+ if ( error ) {
159
+ request . log . error ( { error, request : extractRequestForLogging ( request ) } )
160
+ reply . code ( 400 )
161
+ if ( error . message . startsWith ( 'Cannot find' ) ) reply . code ( 404 )
162
+ return { error : error . message }
163
+ }
164
+
165
+ return data
166
+ }
167
+ )
168
+
167
169
fastify . patch (
168
170
'/:id(\\d+\\.\\d+)' ,
169
171
{
@@ -187,7 +189,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
187
189
const connectionString = request . headers . pg
188
190
189
191
const pgMeta = new PostgresMeta ( { ...DEFAULT_POOL_CONFIG , connectionString } )
190
- const { data, error } = await pgMeta . columns . update ( request . params . id , request . body as any )
192
+ const { data, error } = await pgMeta . columns . update ( request . params . id , request . body )
191
193
await pgMeta . end ( )
192
194
if ( error ) {
193
195
request . log . error ( { error, request : extractRequestForLogging ( request ) } )
@@ -199,6 +201,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
199
201
return data
200
202
}
201
203
)
204
+
202
205
fastify . delete (
203
206
'/:id(\\d+\\.\\d+)' ,
204
207
{
0 commit comments