app-template/packages/dao/AGENTS.md

40 lines
1.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# AGENTS.md — @app/dao
## 职责
**数据访问层(DAO)**:封装 Drizzle 查询(`userDao` / `sessionDao` / `passwordResetDao`)。service 只调本包,不直接 `db.select`。不含业务规则、HTTP/tRPC。
## 结构
```
src/
index.ts # 出口:daos + 行类型
users.ts # userDao
sessions.ts # sessionDao
password-resets.ts # passwordResetDao
```
## 依赖
- `@app/db`:`db` 单例(连接)
- `@app/models`:表定义与 `$infer*` 行类型
## 约定
- 一表一个 dao 对象;方法名 `list` / `getById` / `create` / `update` / `delete`。
- `exactOptionalPropertyTypes`:update 入参用 `Partial<Omit<Row, "id" | "createdAt" | "updatedAt">>`。
- `noUncheckedIndexedAccess`:`returning()[0]` 判空后抛错或 `?? null`。
- 不读 env、不建 client;环境变量校验在 `@app/db`。
## 修改指南
- 加查询:新建或扩展对应 `*.ts`,在 `index.ts` 导出。
- 新表:先改 `@app/models` → `yarn db:generate`/`db:push` → 本包加 dao。
## 命令
```bash
yarn workspace @app/dao typecheck
yarn workspace @app/dao build
```