2025-03-27 16:27:41 +08:00

42 lines
1022 B
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.

# 数据模型
此目录包含应用程序的数据库模型定义使用GORM作为ORM框架
## 模型说明
- `base.go`: 包含基础模型结构
- `robot.go`: 微信机器人模型,保存容器信息和微信账号信息
- `contact.go`: 联系人模型,包括好友和群组
- `group_member.go`: 群成员模型,存储群成员信息
- `message.go`: 消息模型,存储聊天记录
- `db.go`: 数据库连接及初始化
## 数据模型关系
1. 一个机器人(Robot)有多个联系人(Contact)
2. 一个群组(Contact中type为group)有多个群成员(GroupMember)
3. 消息(Message)关联到机器人和联系人,记录具体的聊天内容
## 使用方法
初始化数据库连接:
```go
import (
"github.com/Lxh/wechat-demo/internal/config"
"github.com/Lxh/wechat-demo/internal/model"
)
func main() {
cfg, _ := config.Load()
err := model.InitDB(&cfg.Database)
if err != nil {
panic(err)
}
// 使用DB实例
db := model.GetDB()
// ...
}
```