// Package database define database operation functions package database import ( "context" "time" "modelRT/config" "modelRT/orm" "github.com/gofrs/uuid" "github.com/panjf2000/ants/v2" "go.uber.org/zap" "gorm.io/gorm" "gorm.io/gorm/clause" ) // QueryCircuitDiagramComponentFromDB return the result of query circuit diagram component info order by page id from postgresDB func QueryCircuitDiagramComponentFromDB(ctx context.Context, tx *gorm.DB, pool *ants.PoolWithFunc, logger *zap.Logger) error { var components []orm.Component // ctx超时判断 cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() result := tx.WithContext(cancelCtx).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&components) if result.Error != nil { logger.Error("query circuit diagram component info failed", zap.Error(result.Error)) return result.Error } for _, component := range components { pool.Invoke(config.ModelParseConfig{ ComponentInfo: component, Context: ctx, }) } return nil } // QueryComponentByUUID return the result of query circuit diagram component info by uuid from postgresDB func QueryComponentByUUID(ctx context.Context, tx *gorm.DB, uuid uuid.UUID) (orm.Component, error) { var component orm.Component // ctx超时判断 cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() result := tx.WithContext(cancelCtx).Where("global_uuid = ? ", uuid).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&component) if result.Error != nil { return orm.Component{}, result.Error } return component, nil }