collection

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DocumentFile          = "document_dbs"
	DefaultIndexFieldName = "id"
)
View Source
const (
	LeafEntry         = "L"
	IntermediateEntry = "I"
)
View Source
const (
	CSVHeaderKey = "__csv_header__"
)

Variables

View Source
var (
	ErrEmptyIndex                     = errors.New("empty Index")
	ErrEntryNotFound                  = errors.New("entry not found")
	ErrNoNextElement                  = errors.New("no next element")
	ErrNoManifestFound                = errors.New("no Manifest found")
	ErrManifestUnmarshall             = errors.New("could not unmarshall Manifest")
	ErrManifestCreate                 = errors.New("could not create new Manifest")
	ErrDeleteingIndex                 = errors.New("could not delete index")
	ErrIndexAlreadyPresent            = errors.New("index already present")
	ErrIndexNotPresent                = errors.New("index not present")
	ErrIndexNotSupported              = errors.New("index not supported")
	ErrInvalidIndexType               = errors.New("invalid index type")
	ErrKvTableAlreadyPresent          = errors.New("kv table already present")
	ErrKVTableNotPresent              = errors.New("kv table not present")
	ErrKVTableNotOpened               = errors.New("kv table not opened")
	ErrKVInvalidIndexType             = errors.New("kv invalid index type")
	ErrKVIndexTypeNotSupported        = errors.New("kv index type not supported yet")
	ErrKVKeyNotANumber                = errors.New("kv key not a number")
	ErrUnmarshallingDBSchema          = errors.New("could not unmarshall document db schema")
	ErrMarshallingDBSchema            = errors.New("could not marshall document db schema")
	ErrDocumentDBAlreadyPresent       = errors.New("document db already present")
	ErrDocumentDBNotPresent           = errors.New("document db  not present")
	ErrDocumentDBNotOpened            = errors.New("document db not opened")
	ErrDocumentDBAlreadyOpened        = errors.New("document db already opened")
	ErrDocumentDBIndexFieldNotPresent = errors.New("document db index field not present")
	ErrModifyingImmutableDocDB        = errors.New("trying to modify immutable document db")
	ErrInvalidOperator                = errors.New("invalid operator")
	ErrDocumentNotPresent             = errors.New("document not present")
	ErrInvalidDocumentId              = errors.New("invalid document id")
	ErrReadOnlyIndex                  = errors.New("read only index")
	ErrCannotModifyImmutableIndex     = errors.New("trying to modify immutable index")
	ErrCouldNotUpdatePostageBatch     = errors.New("could not procure new postage batch")
	ErrUnknownJsonFormat              = errors.New("unknown json format")
)
View Source
var (
	NoOfParallelWorkers = runtime.NumCPU() * 4
)

Functions

func CreateIndex

func CreateIndex(podName, collectionName, indexName string, indexType IndexType, fd *feed.API, user utils.Address, client blockstore.Client, mutable bool) error

CreateIndex creates a common index file to be used in kv or document tables.

Types

type Batch

type Batch struct {
	// contains filtered or unexported fields
}

func NewBatch

func NewBatch(idx *Index) (*Batch, error)

NewBatch creates a new batch index to be used in a KV table or a Document database.

func (*Batch) Del

func (b *Batch) Del(key string) ([][]byte, error)

Del deletes a index entry.

func (*Batch) DelNumber

func (b *Batch) DelNumber(key float64) ([][]byte, error)

DelNumber deletes a number index key and value.

func (*Batch) Get

func (b *Batch) Get(key string) ([][]byte, error)

Get extracts a index value from an index givena key.

func (*Batch) Put

func (b *Batch) Put(key string, refValue []byte, apnd, memory bool) error

Put creates a index entry given a key string and value.

func (*Batch) PutNumber

func (b *Batch) PutNumber(key float64, refValue []byte, apnd, memory bool) error

PutNumber inserts index as a number.

func (*Batch) Write

func (b *Batch) Write(podFile string) (*Manifest, error)

Write commits the raw index file in to the Swarm network.

type CIndex

type CIndex struct {
	SimpleIndexes []SIndex
}

type DBSchema

type DBSchema struct {
	Name            string   `json:"name"`
	Mutable         bool     `json:"mutable"`
	SimpleIndexes   []SIndex `json:"simple_indexes,omitempty"`
	MapIndexes      []SIndex `json:"map_indexes,omitempty"`
	ListIndexes     []SIndex `json:"list_indexes,omitempty"`
	CompoundIndexes []CIndex `json:"compound_indexes,omitempty"`
}

type DocBatch

type DocBatch struct {
	// contains filtered or unexported fields
}

type Document

type Document struct {
	// contains filtered or unexported fields
}

func NewDocumentStore

func NewDocumentStore(podName string, fd *feed.API, ai *account.Info, user utils.Address, file *file.File, client blockstore.Client, logger logging.Logger) *Document

NewDocumentStore instantiates a document DB object through which all document DB are spawned.

func (*Document) Count

func (d *Document) Count(dbName, expr string) (uint64, error)

Count counts the number of document in a document DB which matches a given expression

func (*Document) CreateDocBatch

func (d *Document) CreateDocBatch(dbName string) (*DocBatch, error)

CreateDocBatch creates a batch index instead of normal index. This is used when doing a bulk insert.

func (*Document) CreateDocumentDB

func (d *Document) CreateDocumentDB(dbName string, indexes map[string]IndexType, mutable bool) error

CreateDocumentDB creates a new document database and its related indexes.

func (*Document) Del

func (d *Document) Del(dbName, id string) error

Del deletes a specific document from a document database matching a document id.

func (*Document) DeleteDocumentDB

func (d *Document) DeleteDocumentDB(dbName string) error

DeleteDocumentDB a document DB, all its data and its related indxes.

func (*Document) DocBatchPut

func (d *Document) DocBatchPut(docBatch *DocBatch, doc []byte, index int64) error

DocBatchPut is used to insert a single document to the batch index.

func (*Document) DocBatchWrite

func (d *Document) DocBatchWrite(docBatch *DocBatch, podFile string) error

DocBatchWrite commits the batch index into the Swarm network.

func (*Document) DocFileIndex

func (d *Document) DocFileIndex(dbName, podFile string) error

DocFileIndex indexes a existing json file in the pod with the document DB.

func (*Document) Find

func (d *Document) Find(dbName, expr string, limit int) ([][]byte, error)

Find selects a number of rows from a document database matching an expression.

func (*Document) Get

func (d *Document) Get(dbName, id string) ([]byte, error)

Get retrieves a specific document from a document database matching the dcument id.

func (*Document) IsDBOpened

func (d *Document) IsDBOpened(dbName string) bool

IsDBOpened is used to check if a document DB is opened or not.

func (*Document) LoadDocumentDBSchemas

func (d *Document) LoadDocumentDBSchemas() (map[string]DBSchema, error)

LoadDocumentDBSchemas loads the schema of all documents belonging to a pod.

func (*Document) OpenDocumentDB

func (d *Document) OpenDocumentDB(dbName string) error

OpenDocumentDB open a document database and its related indexes.

func (*Document) Put

func (d *Document) Put(dbName string, doc []byte) error

Put inserts a document in to a document database.

type DocumentDB

type DocumentDB struct {
	// contains filtered or unexported fields
}

type Entry

type Entry struct {
	Name     string    `json:"name"`
	EType    string    `json:"type"`
	Ref      [][]byte  `json:"ref,omitempty"`
	Manifest *Manifest `json:"Manifest,omitempty"`
}

type Index

type Index struct {
	// contains filtered or unexported fields
}

func OpenIndex

func OpenIndex(podName, collectionName, indexName string, fd *feed.API, ai *account.Info, user utils.Address, client blockstore.Client, logger logging.Logger) (*Index, error)

OpenIndex open the index and loas any index in to the memory.

func (*Index) CountIndex

func (idx *Index) CountIndex() (uint64, error)

CountIndex counts the entries in an index.

func (*Index) Delete

func (idx *Index) Delete(key string) ([][]byte, error)

Delete removes an entry from index where the key is of type string.

func (*Index) DeleteIndex

func (idx *Index) DeleteIndex() error

DeleteIndex delete the index from file and all its entries.

func (*Index) DeleteNumber

func (idx *Index) DeleteNumber(key float64) ([][]byte, error)

DeleteNumber removes an entry from index where the key is of type number.

func (*Index) Get

func (idx *Index) Get(key string) ([][]byte, error)

Get retrieves an element from the index where the key is of type string.

func (*Index) GetNumber

func (idx *Index) GetNumber(key float64) ([][]byte, error)

GetNumber retrieves an element from the index where the key is of type number.

func (*Index) NewIntIterator

func (idx *Index) NewIntIterator(start, end, limit int64) (*Iterator, error)

NewIntIterator reates a new index iterator with start prefix, endPrefix and the limit to iterate.

func (*Index) NewStringIterator

func (idx *Index) NewStringIterator(start, end string, limit int64) (*Iterator, error)

NewStringIterator creates a new iterator object which is used to create new index iterators.

func (*Index) Put

func (idx *Index) Put(key string, refValue []byte, idxType IndexType, apnd bool) error

Put inserts an entry in to index with a string as key.

func (*Index) PutNumber

func (idx *Index) PutNumber(key float64, refValue []byte, idxType IndexType, apnd bool) error

PutNumber inserts an entry in to index with a number as key.

type IndexType

type IndexType int
const (
	InvalidIndex IndexType = iota
	BytesIndex
	StringIndex
	NumberIndex
	MapIndex
	ListIndex
)

func (IndexType) String

func (e IndexType) String() string

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

func (*Iterator) IntegerKey

func (itr *Iterator) IntegerKey() int64

func (*Iterator) Next

func (itr *Iterator) Next() bool

Next moves the seek pointer one step ahead.

func (*Iterator) Seek

func (itr *Iterator) Seek(key string) error

Seek seeks to the given key prefix.

func (*Iterator) StringKey

func (itr *Iterator) StringKey() string

func (*Iterator) Value

func (itr *Iterator) Value() []byte

func (*Iterator) ValueAll

func (itr *Iterator) ValueAll() [][]byte

type KVCount added in v0.7.0

type KVCount struct {
	Count     uint64 `json:"count"`
	TableName string `json:"table_name"`
}

type KVTable

type KVTable struct {
	// contains filtered or unexported fields
}

type KeyValue

type KeyValue struct {
	// contains filtered or unexported fields
}

func NewKeyValueStore

func NewKeyValueStore(podName string, fd *feed.API, ai *account.Info, user utils.Address, client blockstore.Client, logger logging.Logger) *KeyValue

NewKeyValueStore is the main object used to do all operation on the key value tables.

func (*KeyValue) CreateKVTable

func (kv *KeyValue) CreateKVTable(name string, indexType IndexType) error

CreateKVTable creates the key value table with a given index type.

func (*KeyValue) DeleteKVTable

func (kv *KeyValue) DeleteKVTable(name string) error

DeleteKVTable deletes a given key value table with all it index and data entries.

func (*KeyValue) KVBatch

func (kv *KeyValue) KVBatch(name string, columns []string) (*Batch, error)

KVBatch prepares the index to do a batch insert if keys and values.

func (*KeyValue) KVBatchPut

func (kv *KeyValue) KVBatchPut(batch *Batch, key string, value []byte) error

KVBatchPut inserts a key and value in to the memory for batch.

func (*KeyValue) KVBatchWrite

func (kv *KeyValue) KVBatchWrite(batch *Batch) error

KVBatchWrite commits all the batch entries in to the key value table.

func (*KeyValue) KVCount

func (kv *KeyValue) KVCount(name string) (*KVCount, error)

KVCount counts the number of entries in the given key value table.

func (*KeyValue) KVDelete

func (kv *KeyValue) KVDelete(name, key string) ([]byte, error)

KVDelete removed a key value entry from the KV table given a key.

func (*KeyValue) KVGet

func (kv *KeyValue) KVGet(name, key string) ([]string, []byte, error)

KVGet retrieves a value from the KV table given a key.

func (*KeyValue) KVGetNext

func (kv *KeyValue) KVGetNext(name string) ([]string, string, []byte, error)

KVGetNext retrieve the next key value pair in the iteration.

func (*KeyValue) KVPut

func (kv *KeyValue) KVPut(name, key string, value []byte) error

KVPut inserts a given key and value in to the KV table.

func (*KeyValue) KVSeek

func (kv *KeyValue) KVSeek(name, start, end string, limit int64) (*Iterator, error)

KVSeek seek to given key with start prefix and prepare for iterating the table.

func (*KeyValue) LoadKVTables

func (kv *KeyValue) LoadKVTables() (map[string][]string, error)

LoadKVTables Loads the list of KV tables.

func (*KeyValue) OpenKVTable

func (kv *KeyValue) OpenKVTable(name string) error

OpenKVTable open a given key value table and loads the index.

type Manifest

type Manifest struct {
	Name         string    `json:"name"`
	Mutable      bool      `json:"mutable"`
	PodFile      string    `json:"pod_file,omitempty"`
	IdxType      IndexType `json:"index_type"`
	CreationTime int64     `json:"creation_time"`
	Entries      []*Entry  `json:"entries,omitempty"`
	// contains filtered or unexported fields
}

func NewManifest

func NewManifest(name string, time int64, idxType IndexType, mutable bool) *Manifest

type ManifestState

type ManifestState struct {
	// contains filtered or unexported fields
}

type SIndex

type SIndex struct {
	FieldName string    `json:"name"`
	FieldType IndexType `json:"type"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL