49 lines
743 B
Go
49 lines
743 B
Go
package actions
|
|
|
|
import (
|
|
"jhman/model"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func FindConfigs(tx *gorm.DB) ([]model.Config, error) {
|
|
var configs []model.Config
|
|
err := tx.Find(&configs).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return configs, nil
|
|
}
|
|
|
|
func UpdateConfigs(tx *gorm.DB, configs []model.ConfigUpdate) error {
|
|
if len(configs) == 0 {
|
|
return nil
|
|
}
|
|
|
|
// 批量更新配置
|
|
for _, config := range configs {
|
|
err := tx.
|
|
Where("id = ?", config.Id).
|
|
Updates(&config).
|
|
Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func CreateConfigs(tx *gorm.DB, configs []model.ConfigCreate) error {
|
|
if len(configs) == 0 {
|
|
return nil
|
|
}
|
|
|
|
err := tx.CreateInBatches(&configs, 500).Error
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|