|
- package db
-
- import (
- "time"
-
- cortypes "gitlink.org.cn/cloudream/storage2/coordinator/types"
- )
-
- type HubDB struct {
- *DB
- }
-
- func (db *DB) Hub() *HubDB {
- return &HubDB{DB: db}
- }
-
- func (*HubDB) GetAllHubs(ctx SQLContext) ([]cortypes.Hub, error) {
- var ret []cortypes.Hub
-
- err := ctx.Table("Hub").Find(&ret).Error
- return ret, err
- }
-
- func (*HubDB) GetByID(ctx SQLContext, hubID cortypes.HubID) (cortypes.Hub, error) {
- var ret cortypes.Hub
- err := ctx.Table("Hub").Where("HubID = ?", hubID).Find(&ret).Error
-
- return ret, err
- }
-
- func (*HubDB) BatchGetByID(ctx SQLContext, hubIDs []cortypes.HubID) ([]cortypes.Hub, error) {
- var ret []cortypes.Hub
- err := ctx.Table("Hub").Where("HubID IN (?)", hubIDs).Find(&ret).Error
-
- return ret, err
- }
-
- // UpdateState 更新状态,并且设置上次上报时间为现在
- func (*HubDB) UpdateState(ctx SQLContext, hubID cortypes.HubID, state string) error {
- err := ctx.
- Model(&cortypes.Hub{}).
- Where("HubID = ?", hubID).
- Updates(map[string]interface{}{
- "State": state,
- "LastReportTime": time.Now(),
- }).Error
- return err
- }
|