/** * Todo 表 Schema * * 使用 SQLite 数据类型: * - text: 字符串类型 * - integer: 整数类型 (可配置为 boolean/timestamp 模式) */ import { sql } from 'drizzle-orm' import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core' export const todoTable = sqliteTable('todo', { /** 主键 UUID */ id: text('id') .primaryKey() .$defaultFn(() => crypto.randomUUID()), /** 待办事项标题 */ title: text('title').notNull(), /** 是否已完成 (SQLite 用 0/1 表示布尔值) */ completed: integer('completed', { mode: 'boolean' }).notNull().default(false), /** 创建时间 (Unix 时间戳) */ createdAt: integer('created_at', { mode: 'timestamp' }) .notNull() .default(sql`(unixepoch())`), /** 更新时间 (Unix 时间戳,自动更新) */ updatedAt: integer('updated_at', { mode: 'timestamp' }) .notNull() .default(sql`(unixepoch())`) .$onUpdateFn(() => new Date()), })