- 新增 Go 语言后端服务(server/),包含用户认证、Agent管理、数据库连接等API - 新增 Python Agent 服务(agent/),实现Agent核心逻辑和工具集 - 前端从原生HTML迁移到Vue.js框架(web/src/) - 添加 Docker Compose 支持(docker-compose.yml) - 添加项目架构文档(docs/ARCHITECTURE.md) - 添加环境变量示例(.env.example)和本地启动脚本(start-local.ps1) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package repository
|
|
|
|
import (
|
|
"x-agents/server/internal/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type DatabaseRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewDatabaseRepository(db *gorm.DB) *DatabaseRepository {
|
|
return &DatabaseRepository{db: db}
|
|
}
|
|
|
|
// Create 创建数据库信息
|
|
func (r *DatabaseRepository) Create(info *model.DatabaseInfo) error {
|
|
return r.db.Create(info).Error
|
|
}
|
|
|
|
// FindByID 根据ID查询
|
|
func (r *DatabaseRepository) FindByID(id string) (*model.DatabaseInfo, error) {
|
|
var info model.DatabaseInfo
|
|
err := r.db.First(&info, "id = ?", id).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &info, nil
|
|
}
|
|
|
|
// FindAll 查询所有
|
|
func (r *DatabaseRepository) FindAll() ([]model.DatabaseInfo, error) {
|
|
var list []model.DatabaseInfo
|
|
err := r.db.Order("created_at DESC").Find(&list).Error
|
|
return list, err
|
|
}
|
|
|
|
// Update 更新
|
|
func (r *DatabaseRepository) Update(id string, info *model.DatabaseInfo) error {
|
|
return r.db.Model(&model.DatabaseInfo{}).Where("id = ?", id).Updates(info).Error
|
|
}
|
|
|
|
// Delete 删除
|
|
func (r *DatabaseRepository) Delete(id string) error {
|
|
return r.db.Delete(&model.DatabaseInfo{}, "id = ?", id).Error
|
|
}
|