Beispiel-Konvertierung: PostgreSQL DDL → Drizzle pgTable
Eingabe (PostgreSQL DDL)
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
total_amount NUMERIC(10,2) NOT NULL
); Ausgabe (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(),
}); Häufig gestellte Fragen (FAQ)
Kann ich mit Drizzle TypeScript-Typen exportieren?
Ja! Drizzle stellt den Hilfstyp InferSelectModel<typeof table> bereit, um Datenbanktypen automatisch abzuleiten.