mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-16 18:10:28 +08:00
所有数据库相关的操作支持事务
This commit is contained in:
@@ -35,24 +35,24 @@ func init() {
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
func (this *NodeGroupDAO) EnableNodeGroup(id int64) (rowsAffected int64, err error) {
|
||||
return this.Query().
|
||||
func (this *NodeGroupDAO) EnableNodeGroup(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", NodeGroupStateEnabled).
|
||||
Update()
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
func (this *NodeGroupDAO) DisableNodeGroup(id int64) (rowsAffected int64, err error) {
|
||||
return this.Query().
|
||||
func (this *NodeGroupDAO) DisableNodeGroup(tx *dbs.Tx, id int64) (rowsAffected int64, err error) {
|
||||
return this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", NodeGroupStateDisabled).
|
||||
Update()
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
func (this *NodeGroupDAO) FindEnabledNodeGroup(id int64) (*NodeGroup, error) {
|
||||
result, err := this.Query().
|
||||
func (this *NodeGroupDAO) FindEnabledNodeGroup(tx *dbs.Tx, id int64) (*NodeGroup, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Attr("state", NodeGroupStateEnabled).
|
||||
Find()
|
||||
@@ -63,8 +63,8 @@ func (this *NodeGroupDAO) FindEnabledNodeGroup(id int64) (*NodeGroup, error) {
|
||||
}
|
||||
|
||||
// 根据主键查找名称
|
||||
func (this *NodeGroupDAO) FindNodeGroupName(id int64) (string, error) {
|
||||
name, err := this.Query().
|
||||
func (this *NodeGroupDAO) FindNodeGroupName(tx *dbs.Tx, id int64) (string, error) {
|
||||
name, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Result("name").
|
||||
FindCol("")
|
||||
@@ -72,12 +72,12 @@ func (this *NodeGroupDAO) FindNodeGroupName(id int64) (string, error) {
|
||||
}
|
||||
|
||||
// 创建分组
|
||||
func (this *NodeGroupDAO) CreateNodeGroup(clusterId int64, name string) (int64, error) {
|
||||
func (this *NodeGroupDAO) CreateNodeGroup(tx *dbs.Tx, clusterId int64, name string) (int64, error) {
|
||||
op := NewNodeGroupOperator()
|
||||
op.ClusterId = clusterId
|
||||
op.Name = name
|
||||
op.State = NodeGroupStateEnabled
|
||||
err := this.Save(op)
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -85,20 +85,20 @@ func (this *NodeGroupDAO) CreateNodeGroup(clusterId int64, name string) (int64,
|
||||
}
|
||||
|
||||
// 修改分组
|
||||
func (this *NodeGroupDAO) UpdateNodeGroup(groupId int64, name string) error {
|
||||
func (this *NodeGroupDAO) UpdateNodeGroup(tx *dbs.Tx, groupId int64, name string) error {
|
||||
if groupId <= 0 {
|
||||
return errors.New("invalid groupId")
|
||||
}
|
||||
op := NewNodeGroupOperator()
|
||||
op.Id = groupId
|
||||
op.Name = name
|
||||
err := this.Save(op)
|
||||
err := this.Save(tx, op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 查询所有分组
|
||||
func (this *NodeGroupDAO) FindAllEnabledGroupsWithClusterId(clusterId int64) (result []*NodeGroup, err error) {
|
||||
_, err = this.Query().
|
||||
func (this *NodeGroupDAO) FindAllEnabledGroupsWithClusterId(tx *dbs.Tx, clusterId int64) (result []*NodeGroup, err error) {
|
||||
_, err = this.Query(tx).
|
||||
State(NodeGroupStateEnabled).
|
||||
Attr("clusterId", clusterId).
|
||||
Desc("order").
|
||||
@@ -109,9 +109,9 @@ func (this *NodeGroupDAO) FindAllEnabledGroupsWithClusterId(clusterId int64) (re
|
||||
}
|
||||
|
||||
// 保存排序
|
||||
func (this *NodeGroupDAO) UpdateGroupOrders(groupIds []int64) error {
|
||||
func (this *NodeGroupDAO) UpdateGroupOrders(tx *dbs.Tx, groupIds []int64) error {
|
||||
for index, groupId := range groupIds {
|
||||
_, err := this.Query().
|
||||
_, err := this.Query(tx).
|
||||
Pk(groupId).
|
||||
Set("order", len(groupIds)-index).
|
||||
Update()
|
||||
|
||||
Reference in New Issue
Block a user