milvus/internal/metastore/db/dao/field.go
jaime c9d0c157ec
Move some modules from internal to public package (#22572)
Signed-off-by: jaime <yun.zhang@zilliz.com>
2023-04-06 19:14:32 +08:00

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
}