mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 11:59:00 +08:00
af1f67b9d2
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package reader
|
|
|
|
import "C"
|
|
import (
|
|
"errors"
|
|
)
|
|
|
|
type Collection struct {
|
|
CollectionPtr *C.Collection
|
|
CollectionName string
|
|
}
|
|
|
|
// TODO: Schema
|
|
type CollectionSchema string
|
|
|
|
func NewCollection(collectionName string, schema CollectionSchema) (*Collection, error) {
|
|
cName := C.CString(collectionName)
|
|
cSchema := C.CString(schema)
|
|
collection, status := C.NewCollection(cName, cSchema)
|
|
|
|
if status != 0 {
|
|
return nil, errors.New("create collection failed")
|
|
}
|
|
|
|
return &Collection{CollectionPtr: collection, CollectionName: collectionName}, nil
|
|
}
|
|
|
|
func DeleteCollection(collection *Collection) error {
|
|
status := C.DeleteCollection(collection.CollectionPtr)
|
|
|
|
if status != 0 {
|
|
return errors.New("delete collection failed")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (c *Collection) GetSegments() ([]*Segment, error) {
|
|
segments, status := C.GetSegments(c.CollectionPtr)
|
|
|
|
if status != 0 {
|
|
return nil, errors.New("get segments failed")
|
|
}
|
|
|
|
return segments, nil
|
|
}
|
|
|
|
func (c *Collection) CreateSegment() error {
|
|
status := C.CreateSegment(c.CollectionPtr)
|
|
|
|
if status != 0 {
|
|
return errors.New("create segment failed")
|
|
}
|
|
|
|
return nil
|
|
}
|