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