mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 21:09:06 +08:00
c9d0c157ec
Signed-off-by: jaime <yun.zhang@zilliz.com>
37 lines
984 B
Go
37 lines
984 B
Go
package dao
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/milvus-io/milvus/internal/metastore/db/dbmodel"
|
|
"github.com/milvus-io/milvus/pkg/log"
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
|
)
|
|
|
|
type fieldDb struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func (s *fieldDb) GetByCollectionID(tenantID string, collectionID typeutil.UniqueID, ts typeutil.Timestamp) ([]*dbmodel.Field, error) {
|
|
var r []*dbmodel.Field
|
|
|
|
err := s.db.Model(&dbmodel.Field{}).Where("tenant_id = ? AND collection_id = ? AND ts = ? AND is_deleted = false", tenantID, collectionID, ts).Find(&r).Error
|
|
if err != nil {
|
|
log.Error("get fields by collection_id and ts failed", zap.String("tenant", tenantID), zap.Int64("collID", collectionID), zap.Uint64("ts", ts), zap.Error(err))
|
|
return nil, err
|
|
}
|
|
|
|
return r, nil
|
|
}
|
|
|
|
func (s *fieldDb) Insert(in []*dbmodel.Field) error {
|
|
err := s.db.CreateInBatches(in, 100).Error
|
|
if err != nil {
|
|
log.Error("insert field failed", zap.Error(err))
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|