refactor(db): added type export with zod
This commit is contained in:
@@ -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>;
|
||||||
|
|||||||
Reference in New Issue
Block a user