refactor(db): added type export with zod

This commit is contained in:
2025-08-31 21:36:09 -05:00
parent 2e51474a5e
commit 8eefbe9df0

View File

@@ -1,4 +1,3 @@
import type { InferInsertModel, InferSelectModel } from "drizzle-orm";
import { import {
text, text,
pgTable, pgTable,
@@ -8,6 +7,9 @@ import {
jsonb, jsonb,
boolean, boolean,
} from "drizzle-orm/pg-core"; } from "drizzle-orm/pg-core";
import { createInsertSchema, createSelectSchema } from "drizzle-zod";
import { z } from "zod";
export const settings = pgTable( export const settings = pgTable(
"settings", "settings",
@@ -30,5 +32,12 @@ export const settings = pgTable(
] ]
); );
export type Setting = InferSelectModel<typeof settings>; export const settingSchema = createSelectSchema(settings);
export type NewSetting = InferInsertModel<typeof settings>; export const newSettingSchema = createInsertSchema(settings, {
name: z.string().min(3, {
message: "The name of the setting must be longer than 3 letters",
}),
});
export type Setting = z.infer<typeof settingSchema>;
export type NewSetting = z.infer<typeof newSettingSchema>;