-
-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: batch endpoints for column creation and retrieval #206
base: master
Are you sure you want to change the base?
Conversation
2fd95fc
to
f5a6782
Compare
src/server/routes/columns.ts
Outdated
@@ -54,6 +55,26 @@ export default async (fastify: FastifyInstance) => { | |||
return data | |||
}) | |||
|
|||
fastify.get<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opted to expose these separately rather than have the existing endpoints handle both cases; it gets annoying with the GET accepting a single ID param (and just gnarly in any case).
We can replace the current endpoint as part of a breaking change in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Couple of minor suggestions
src/lib/PostgresMetaColumns.ts
Outdated
if (!regexp.test(id)) { | ||
return { data: null, error: { message: 'Invalid format for column ID' } } | ||
|
||
const invalidId = ids.find((id) => !regexp.test(id)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would recommend findAll (or equivalent) here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
table, | ||
schema = 'public', | ||
}: { | ||
ids?: string[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really dislike this way of everything being optional - can we use a discriminated union type instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a TS thing - the 2 function declaration above it means it's either ids
or names
+ table
+ schema
}), | ||
body: Type.Union([postgresColumnCreateSchema, Type.Array(postgresColumnCreateSchema)]), | ||
response: { | ||
200: Type.Union([postgresColumnSchema, Type.Array(postgresColumnSchema)]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we wanted to be really nice about it, would be cool to pluck the table name out of the array, since we don't allow multiple different values for the field here anyway
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to make the response format consistent: T | T[]
for everything
d649ad0
to
358f683
Compare
Makes the Array.isArray check at the end always true
existing tests pass