28 lines
702 B
Go
28 lines
702 B
Go
// Package database define database operation functions
|
|
package database
|
|
|
|
import (
|
|
"modelRT/orm"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// GenAllAttributeMap define func to query global_uuid、component tag、component nspath field for attribute group
|
|
func GenAllAttributeMap(db *gorm.DB) (map[string]orm.AttributeSet, error) {
|
|
var compResults []orm.Component
|
|
resMap := make(map[string]orm.AttributeSet)
|
|
|
|
err := db.Model(&orm.Component{}).Select("global_uuid", "station_id", "tag", "nspath").Find(&compResults).Error
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, r := range compResults {
|
|
resMap[r.GlobalUUID.String()] = orm.AttributeSet{
|
|
CompTag: r.Tag,
|
|
CompNSPath: r.NSPath,
|
|
}
|
|
}
|
|
return resMap, nil
|
|
}
|