feat: 迁移数据库至 SQLite 并新增项目文档

- 将 Postgres 数据库替换为 SQLite
- 并同步添加 README 文档以优化项目初始化流程
This commit is contained in:
2026-01-20 16:56:11 +08:00
parent 5513979ebc
commit b967deb4b1
14 changed files with 482 additions and 78 deletions

View File

@@ -1,3 +1,9 @@
/**
* Todo API 契约
*
* 使用 ORPC 契约定义 API 的输入/输出类型。
* drizzle-zod 自动从表 schema 生成验证规则。
*/
import { oc } from '@orpc/contract'
import {
createInsertSchema,
@@ -7,24 +13,34 @@ import {
import { z } from 'zod'
import { todoTable } from '@/db/schema'
/** 查询返回的完整 Todo 类型 */
const selectSchema = createSelectSchema(todoTable)
/** 创建 Todo 时的输入类型 (排除自动生成的字段) */
const insertSchema = createInsertSchema(todoTable).omit({
id: true,
createdAt: true,
updatedAt: true,
})
/** 更新 Todo 时的输入类型 (所有字段可选) */
const updateSchema = createUpdateSchema(todoTable).omit({
id: true,
createdAt: true,
updatedAt: true,
})
// ============================================================
// API 契约定义
// ============================================================
/** 获取所有 Todo */
export const list = oc.input(z.void()).output(z.array(selectSchema))
/** 创建新 Todo */
export const create = oc.input(insertSchema).output(selectSchema)
/** 更新 Todo */
export const update = oc
.input(
z.object({
@@ -34,6 +50,7 @@ export const update = oc
)
.output(selectSchema)
/** 删除 Todo */
export const remove = oc
.input(
z.object({