mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 16:45:55 +00:00
This commit adds the pilosactl binary with a single `import` command. The import allows users to bulk import data from a CSV file.
46 lines
1,013 B
Go
46 lines
1,013 B
Go
package pilosa_test
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/umbel/pilosa"
|
|
)
|
|
|
|
// Index is a test wrapper for pilosa.Index.
|
|
type Index struct {
|
|
*pilosa.Index
|
|
}
|
|
|
|
// NewIndex returns a new instance of Index with a temporary path.
|
|
func NewIndex() *Index {
|
|
path, err := ioutil.TempDir("", "pilosa-")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &Index{Index: pilosa.NewIndex(path)}
|
|
}
|
|
|
|
// MustOpenIndex creates and opens an index at a temporary path. Panic on error.
|
|
func MustOpenIndex() *Index {
|
|
i := NewIndex()
|
|
if err := i.Open(); err != nil {
|
|
panic(err)
|
|
}
|
|
return i
|
|
}
|
|
|
|
// Close closes the index and removes all underlying data.
|
|
func (i *Index) Close() error {
|
|
defer os.RemoveAll(i.Path())
|
|
return i.Index.Close()
|
|
}
|
|
|
|
// MustCreateFragmentIfNotExists returns a given fragment. Panic on error.
|
|
func (i *Index) MustCreateFragmentIfNotExists(db, frame string, slice uint64) *Fragment {
|
|
f, err := i.Index.CreateFragmentIfNotExists(db, frame, slice)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return &Fragment{Fragment: f}
|
|
}
|