Documentation
¶
Index ¶
- Variables
- type Bounds
- type DB
- type Document
- func (v Document) Decode(dst interface{}) error
- func (v Document) QueryAll(query string) []interface{}
- func (v Document) QueryBytes(query string) []byte
- func (v Document) QueryFloat64(query string) float64
- func (v Document) QueryInt(query string) int
- func (v Document) QueryInt64(query string) int64
- func (v Document) QueryOne(query string) interface{}
- func (v Document) QueryString(query string) string
- func (v Document) QueryTime(query string) time.Time
- type Index
- func (i *Index) All(reverse ...bool) *Range
- func (i *Index) Between(lower, upper interface{}, reverse ...bool) *Range
- func (i *Index) CountBetween(lower, upper interface{}) int64
- func (i *Index) Drop() error
- func (i *Index) GetAll(key interface{}) *Range
- func (i *Index) One(key interface{}, dst interface{}) (string, uint64, error)
- type Name
- type Range
- func (r *Range) All(dst interface{}) error
- func (r *Range) Close()
- func (r *Range) Count() (int64, error)
- func (r *Range) Counter() uint64
- func (r *Range) Decode(dst interface{}) error
- func (r *Range) Do(operation func(key string, counter uint64, doc Document) error, workers ...int) error
- func (r *Range) Document() Document
- func (r *Range) Error() error
- func (r *Range) Filter(filter func(doc Document) (bool, error), workers ...int) *Range
- func (r *Range) Key() string
- func (r *Range) Limit(n int64) *Range
- func (r *Range) Next() bool
- func (r *Range) Skip(n int) *Range
- func (r *Range) Unique() *Range
- type Table
- func (t *Table) All(reverse ...bool) *Range
- func (t *Table) Between(lower interface{}, upper interface{}, reverse ...bool) *Range
- func (t *Table) CountBetween(lower, upper interface{}) int64
- func (t *Table) Delete(key string, counter ...uint64) error
- func (t *Table) Drop() error
- func (t *Table) Get(key string, dst interface{}) (uint64, error)
- func (t *Table) Index(index string) *Index
- func (t *Table) Indexes() []string
- func (t *Table) NewIndex(name string) error
- func (t *Table) Set(key string, value interface{}, counter ...uint64) error
- func (t *Table) Update(key string, handler interface{}) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrAlreadyExists = errors.New("cete: already exists") ErrNotFound = errors.New("cete: not found") ErrBadIdentifier = errors.New("cete: bad identifier") ErrEndOfRange = errors.New("cete: end of range") ErrCounterChanged = errors.New("cete: counter changed") ErrIndexError = errors.New("cete: index error") )
Common errors that can be returned
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB represents the database.
func Open ¶
Open opens the database at the provided path. It will create a new database if the folder does not exist.
func (*DB) Close ¶
func (d *DB) Close()
Close closes the database (all file handlers to the database).
func (*DB) NewTable ¶
NewTable creates a new table in the database. You can optionally specify to disable transparent key compression by setting the second parameter to false. Transparent key compression is enabled by default. Disable it if your the keys in your document are very dynamic, as the key compression map is stored in memory.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document represents the value of a document.
func (Document) QueryBytes ¶
QueryBytes returns the []byte value of a QueryOne assumed to contain a []byte.
func (Document) QueryFloat64 ¶
QueryFloat64 returns the float64 value of a QueryOne assumed to contain a float64.
func (Document) QueryInt64 ¶
QueryInt64 returns the int64 value of a QueryOne assumed to contain an int64.
func (Document) QueryString ¶
QueryString returns the string value of a QueryOne assumed to contain a string.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index represents an index of a table.
func (*Index) All ¶
All returns all the documents which have an index value. It is shorthand for Between(MinValue, MaxValue, reverse...)
func (*Index) Between ¶
Between returns a Range of documents between the lower and upper index values provided. The range will be sorted in ascending order by index value. You can reverse the sorting by specifying true to the optional reverse parameter. The bounds are inclusive on both ends. It is possible to have duplicate documents if the same document has multiple unique index values. To remove filter duplicate documents, use `Unique()` on the Range.
You can use cete.MinValue and cete.MaxValue to specify minimum and maximum bound values.
func (*Index) CountBetween ¶
CountBetween returns the number of documents whose index values are within the given bounds. It is an optimized version of Between(lower, upper).Count(). Note that like with Between, double counting for documents is possible if the document has multiple unique index values.
func (*Index) Drop ¶
Drop drops the index from the table, deleting its folder from the disk. All further calls to the index will result in undefined behaviour. Note that table.Index("deleted index") will be nil.
func (*Index) GetAll ¶
GetAll returns all the matching values as a range for the provided index key.
func (*Index) One ¶
One puts the first matching value with the index's key into dst. dst must either be a pointer or nil if you would like to only get the key/counter and check for existence. Note that indexes are non-unique, a single index key can map to multiple values. Use GetAll to get all such matching values.
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range represents a result with multiple values in it and is usually sorted by index/key.
func (*Range) All ¶
All stores all of the results into slice dst provided by as a pointer. A nil error will be returned if the range reaches ErrEndOfRange.
func (*Range) Close ¶
func (r *Range) Close()
Close closes the range. The range will automatically close upon the first encountered error.
func (*Range) Count ¶
Count will count the number of elements in the range and consume the values in the range. If it reaches the end of the range, it will return the count with a nil error. If a non-nil error is encountered, it returns the current count and the error.
func (*Range) Do ¶
func (r *Range) Do(operation func(key string, counter uint64, doc Document) error, workers ...int) error
Do applies a operation onto the range concurrently. Order is not guaranteed. If the operation returns an error, Do will stop and return the error. An error with the operation may not stop Do immediately, as the range buffer must be exhausted first. Errors during the range will also be returned. A nil error will be returned if ErrEndOfRange is reached.
You can optionally specify the number of workers to concurrently operate on. By default the number of workers is 10.
func (*Range) Error ¶
Error returns the last error causing Next to return false. It will be nil if Next returned true.
func (*Range) Filter ¶
Filter applies a filter onto the range, skipping values where the provided filter returns false. If the filter returns a non-nil error, the range will be stopped, and the error will be returned.
You can optionally specify the number of workers to concurrently operate the filter to speed up long running filter queries. Note that you will still be limited by the read speed, and having too many workers will increase concurrency overhead. The default number of workers is 5.
func (*Range) Limit ¶
Limit limits the number of documents that can be read from the range. When this limit is reached, ErrEndOfRange will be returned.
func (*Range) Next ¶
Next retrieves the next item in the range, and returns true if the next item is successfully retrieved.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a table in the database.
func (*Table) All ¶
All returns all the documents in the table. It is shorthand for Between(MinValue, MaxValue, reverse...)
func (*Table) Between ¶
Between returns a Range of documents between the lower and upper key values provided. The range will be sorted in ascending order by key. You can reverse the sorting by specifying true to the optional reverse parameter. The bounds are inclusive on both ends.
You can use cete.MinValue and cete.MaxValue to specify minimum and maximum bound values.
func (*Table) CountBetween ¶
CountBetween returns the number of documents whose key values are within the given inclusive bounds. Lower and upper must be strings or Bounds. It's an optimized version of Between(lower, upper).Count().
func (*Table) Delete ¶
Delete deletes the key from the table. An optional counter value can be provided to only delete the document if the counter value is the same.
func (*Table) Get ¶
Get retrieves a value from a table with its primary key. dst must either be a pointer or nil if you only want to get the counter or check for existence.
func (*Table) Index ¶
Index returns the index object of an index of the table. If the index does not exist, nil is returned.
func (*Table) NewIndex ¶
NewIndex creates a new index on the table, using the name as the Query. The index name must not be empty, and must be no more than 125 bytes long. ErrAlreadyExists will be returned if the index already exists.
NewIndex may take a while if there are already values in the table, as it needs to index all the existing values in the table.
func (*Table) Set ¶
Set sets a value in the table. An optional counter value can be provided to only set the value if the counter value is the same. A counter value of 0 is valid and represents a key that doesn't exist.
func (*Table) Update ¶
Update updates a document in the table with the given modifier function. The modifier function should take in 1 argument, the variable to decode the current document value into. The modifier function should return 2 values, the new value to set the document to, and an error which determines whether or not the update should be aborted, and will be returned back from Update.
ErrNotFound will be returned if the document does not exist.
The modifier function will be continuously called until the counter at the beginning of handler matches the counter when the document is updated. This allows for safe updates on a single document, such as incrementing a value.