collection.go 974 字节
Newer Older
B
bigsheeper 已提交
1 2 3 4 5 6 7 8 9 10
package reader

import "C"
import (
	"errors"
)

type Collection struct {
	CollectionPtr *C.Collection
	CollectionName string
11
	Partitions []*Partition
B
bigsheeper 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
}

// 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
}