Table Schemas
When defining Drizzle table schemas, please follow these guidelines.
Data Types
JSON Data: Use
textwith{ mode: "json" }for JSON datatypescriptpreferences: text("preferences", { mode: "json" }).$type<string[]>(), metadata: text("metadata", { mode: "json" }).$type<Record<string, unknown>>(),Timestamps: Use
integerwith{ mode: "timestamp" }for datestypescriptcreated_at: integer("created_at", { mode: "timestamp" }).notNull(), updated_at: integer("updated_at", { mode: "timestamp" }).notNull(),Currency: Use
integerfor monetary values (store in cents or other lowest denomination)typescriptprice: integer("price").notNull(),
Indexes
Use the array syntax within the table definition to define indexes.
typescriptimport { integer, text, index, uniqueIndex, sqliteTable, } from "drizzle-orm/sqlite-core"; export const user = sqliteTable( "user", { id: text("id").primaryKey({ autoIncrement: true }), name: text("name"), email: text("email"), }, (table) => [ index("name_idx").on(table.name), uniqueIndex("email_idx").on(table.email), ], );