Documentation ¶
Index ¶
- Variables
- type DataRecord
- type DataStore
- type Table
- func (t *Table) CreateIndex(index string, nilFirst bool, fields ...uint64) error
- func (t *Table) Delete(index string, key DataRecord) error
- func (t *Table) ForEach(index string, callback func(k, v []byte) error) error
- func (t *Table) Get(index string, key, res DataRecord) error
- func (t *Table) Put(rec DataRecord) (uint64, error)
- func (t *Table) Scan(index string, ascending bool, start, res DataRecord, ...) error
- func (t *Table) String() string
Constants ¶
This section is empty.
Variables ¶
var ( NO_TABLE = bolt.ErrBucketNotFound NO_INDEX = bolt.ErrBucketNotFound ALREADY_EXISTS = bolt.ErrBucketExists NO_SCHEMA = errors.New("no schema for table") SCHEMA_CORRUPTED = errors.New("schema corrupted") NO_KEY = errors.New("key not found") BAD_VALUES = errors.New("bad values") // this is just a marker for auto-increment fields AUTOINCREMENT = &struct{}{} )
Functions ¶
This section is empty.
Types ¶
type DataRecord ¶
type DataRecord interface { ToFieldList() []interface{} FromFieldList([]interface{}) }
A DataRecord is the interface for elements that can be stored in a table. A DataRecord needs to implement two methods:
ToFieldList() should convert the record fields into a list of values, preserving their order (i.e. the same fields should always be in the same position)
FromFieldList() should fill the record with values from the input list. The order of values is the same as what was returned from ToFieldList()
type DataStore ¶
A DataStore is the main interface to a BoltDB database
func (*DataStore) CreateTable ¶
Create table if doesn't exist
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
A Table is a container for the table name and indices
func (*Table) CreateIndex ¶
Create an index given the name (index) and a list of field positions used to create a composite key.
nilFirst specifies if nil values should sort first (lowest possible value) or last (highest possible value)
The field position should corrispond to the entries in DataRecord ToFieldList() and FromFieldList()
func (*Table) Delete ¶
func (t *Table) Delete(index string, key DataRecord) error
Delete a record from the table, given the index and the key
func (*Table) ForEach ¶
Scan through all records in an index. Calls specified callback with key and value (as []byte, not decoded)
func (*Table) Get ¶
func (t *Table) Get(index string, key, res DataRecord) error
Get a record from the table, given the index and the key
func (*Table) Put ¶
func (t *Table) Put(rec DataRecord) (uint64, error)
Add a record to the table, updating all indices. If a record with the same key exists, it's updated.
func (*Table) Scan ¶
func (t *Table) Scan(index string, ascending bool, start, res DataRecord, callback func(DataRecord, error) bool) error
Get all records sorted by index keys (ascending or descending) Call user function with record content or error