27 lines
676 B
Go
27 lines
676 B
Go
// Package database define database operation functions
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"modelRT/orm"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
// QueryGridByName return the result of query circuit diagram grid info by tagName from postgresDB
|
|
func QueryGridByName(ctx context.Context, tx *gorm.DB, tagName string) (orm.Grid, error) {
|
|
var grid orm.Grid
|
|
// ctx超时判断
|
|
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
|
defer cancel()
|
|
|
|
result := tx.WithContext(cancelCtx).Where("TAGNAME = ? ", tagName).Clauses(clause.Locking{Strength: "UPDATE"}).Find(&grid)
|
|
if result.Error != nil {
|
|
return orm.Grid{}, result.Error
|
|
}
|
|
return grid, nil
|
|
}
|