Skip to content

Commit 35675ee

Browse files
committed
update types
1 parent e08eb30 commit 35675ee

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

src/lib/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const postgresColumnCreateSchema = Type.Object({
4747
table_id: Type.Integer(),
4848
name: Type.String(),
4949
type: Type.String(),
50-
default_value: Type.Optional(Type.String()),
50+
default_value: Type.Optional(Type.Unknown()),
5151
default_value_format: Type.Optional(
5252
Type.Union([Type.Literal('expression'), Type.Literal('literal')])
5353
),
@@ -67,7 +67,7 @@ export const postgresColumnUpdateSchema = Type.Object({
6767
name: Type.Optional(Type.String()),
6868
type: Type.Optional(Type.String()),
6969
drop_default: Type.Optional(Type.Boolean()),
70-
default_value: Type.Optional(Type.String()),
70+
default_value: Type.Optional(Type.Unknown()),
7171
default_value_format: Type.Optional(
7272
Type.Union([Type.Literal('expression'), Type.Literal('literal')])
7373
),
@@ -78,7 +78,7 @@ export const postgresColumnUpdateSchema = Type.Object({
7878
is_nullable: Type.Optional(Type.Boolean()),
7979
is_unique: Type.Optional(Type.Boolean()),
8080
comment: Type.Optional(Type.String()),
81-
check: Type.Optional(Type.String()),
81+
check: Type.Optional(Type.Union([Type.String(), Type.Null()])),
8282
})
8383
export type PostgresColumnUpdate = Static<typeof postgresColumnUpdateSchema>
8484

src/server/routes/columns.ts

+36-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { FastifyInstance } from 'fastify'
21
import { PostgresMeta } from '../../lib/index.js'
32
import { DEFAULT_POOL_CONFIG } from '../constants.js'
43
import { extractRequestForLogging } from '../utils.js'
@@ -59,38 +58,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
5958
return data
6059
}
6160
)
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-
}
9061

91-
return data
92-
}
93-
)
9462
fastify.get(
9563
'/:tableId(^\\d+):ordinalPosition',
9664
{
@@ -164,6 +132,40 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
164132
}
165133
}
166134
)
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+
167169
fastify.patch(
168170
'/:id(\\d+\\.\\d+)',
169171
{
@@ -187,7 +189,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
187189
const connectionString = request.headers.pg
188190

189191
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)
191193
await pgMeta.end()
192194
if (error) {
193195
request.log.error({ error, request: extractRequestForLogging(request) })
@@ -199,6 +201,7 @@ const route: FastifyPluginAsyncTypebox = async (fastify) => {
199201
return data
200202
}
201203
)
204+
202205
fastify.delete(
203206
'/:id(\\d+\\.\\d+)',
204207
{

0 commit comments

Comments
 (0)