32 lines
970 B
Go
32 lines
970 B
Go
// Package database define database operation functions
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"modelRT/constant"
|
|
"modelRT/network"
|
|
"modelRT/orm"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// DeleteTopologicIntoDB define delete topologic info of the circuit diagram query by pageID and topologic info
|
|
func DeleteTopologicIntoDB(ctx context.Context, tx *gorm.DB, pageID int64, delInfo network.TopologicUUIDDelInfos) error {
|
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
defer cancel()
|
|
|
|
result := tx.Model(&orm.Topologic{}).WithContext(cancelCtx).Where("page_id = ? and uuid_from = ? and uuid_to = ?", pageID, delInfo.UUIDFrom, delInfo.UUIDTo).Delete(&orm.Topologic{})
|
|
|
|
if result.Error != nil || result.RowsAffected == 0 {
|
|
err := result.Error
|
|
if result.RowsAffected == 0 {
|
|
err = fmt.Errorf("%w:please check delete topologic where conditions", constant.ErrDeleteRowZero)
|
|
}
|
|
return fmt.Errorf("delete topologic link failed:%w", err)
|
|
}
|
|
return nil
|
|
}
|