- 新增 Neo4j 图数据库 handler、service、model - 后端添加 SaveGraph API 接口 - 前端 Database.vue 重构,拆分为独立组件 - 新增 web/src/views/database/ 组件目录 - 删除临时文件 (temp_*.go) - 添加 Neo4j 相关 API 需求文档 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
53 lines
1.3 KiB
Go
53 lines
1.3 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
|
|
}
|
|
|
|
// UpdateFields 更新指定字段
|
|
func (r *DatabaseRepository) UpdateFields(id string, fields map[string]interface{}) error {
|
|
return r.db.Model(&model.DatabaseInfo{}).Where("id = ?", id).Updates(fields).Error
|
|
}
|
|
|
|
// Delete 删除
|
|
func (r *DatabaseRepository) Delete(id string) error {
|
|
return r.db.Delete(&model.DatabaseInfo{}, "id = ?", id).Error
|
|
}
|