Ví dụ chuyển đổi: PostgreSQL DDL → Drizzle pgTable
Đầu vào (PostgreSQL DDL)
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
total_amount NUMERIC(10,2) NOT NULL
); Kết quả (Drizzle pgTable)
import { pgTable, serial, numeric } from "drizzle-orm/pg-core";
export const orders = pgTable("orders", {
id: serial("id").primaryKey(),
totalAmount: numeric("total_amount", { precision: 10, scale: 2 }).notNull(),
}); Câu hỏi thường gặp (FAQ)
Tôi có thể xuất kiểu TypeScript trực tiếp từ Drizzle không?
Có! Drizzle cung cấp kiểu InferSelectModel<typeof table> để tự động suy luận kiểu dữ liệu từ bảng cơ sở dữ liệu.