- Published on
Drizzle ORM InferModel
- Authors
- Name
- Shelton Ma
1. Drizzle ORM - Inferring Models with InferModel
import { documents } from "@/db/schema";
import { InferInsertModel, InferSelectModel } from "drizzle-orm";
type Document = InferSelectModel<typeof documents>;
type CreateDocumentData = InferInsertModel<typeof documents>;
// Infer result
type Document = {
id: string;
title: string;
initialContent: string | null;
ownerId: string;
roomId: string | null;
organizationId: string | null;
}
type CreateDocumentData = {
title: string;
ownerId: string;
id?: string | undefined;
initialContent?: string | null | undefined;
roomId?: string | null | undefined;
organizationId?: string | null | undefined;
}