Derive Elysia request validators from Drizzle tables via drizzle-typebox

This commit is contained in:
2026-08-28 17:02:10 +00:00
parent fad0a52690
commit 3f0a51194b
4 changed files with 36 additions and 22 deletions
+22
View File
@@ -0,0 +1,22 @@
import { createInsertSchema, createSelectSchema } from "drizzle-typebox";
import { t } from "elysia";
import { printers, printJobs } from "./schema";
// Generated straight from the Drizzle table definitions in `./schema` — this
// is the *only* place these shapes are defined. The Postgres column and the
// Elysia request/response validator can no longer drift apart: change a
// column in `./schema/printers.ts` and both the DB migration and the API
// validator below pick it up automatically.
//
// The second argument overrides fields Drizzle can't infer correctly for an
// insert — `id` is DB-generated (defaultRandom()) so it must be optional on
// the way in, even though it's required on the way out.
export const PrinterInsertSchema = createInsertSchema(printers, {
id: t.Optional(t.String({ format: "uuid" })),
});
export const PrinterSelectSchema = createSelectSchema(printers);
export const PrintJobInsertSchema = createInsertSchema(printJobs, {
id: t.Optional(t.String({ format: "uuid" })),
});
export const PrintJobSelectSchema = createSelectSchema(printJobs);