Files
digital-psychology/.ai/patterns/repository.md
T
jackyu66gitandCursor 2fb1dfee14 chore: seal Design Vision v1 and monorepo scaffold
Archive the differentiated YuXinGu product docs, AI engineering system,
design contract, and Go/Vue scaffold. Next execution prioritizes Cece-parity
over early innovation (see .ai/product/STRATEGY.md).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-02 16:00:44 +08:00

25 lines
617 B
Markdown

# Pattern: Repository
## Responsibility
Persistence only. Parameterized SQL. Map rows ↔ model.
## Shape
```go
func (r *ReportRepository) SaveReport(ctx context.Context, m *model.Report) error {
const q = `INSERT INTO report (id, user_id, kind, payload, created_at, updated_at)
VALUES ($1,$2,$3,$4,now(),now())`
_, err := r.db.ExecContext(ctx, q, m.ID, m.UserID, m.Kind, m.Payload)
if err != nil {
return fmt.Errorf("insert report: %w", err)
}
return nil
}
```
## Never
- `SELECT *` in new code
- Business policy (VIP checks) here — return data, let service decide