Documentation ¶
Index ¶
- Constants
- Variables
- func ByteToFloat32(bytes []byte) float32
- func ByteToFloat64(bytes []byte) float64
- func BytesToInt64(buf []byte) int64
- func DefaultDecode(data []byte, value interface{}) error
- func DefaultEncode(value interface{}) ([]byte, error)
- func Float32ToByte(float float32) []byte
- func Float64ToByte(float float64) []byte
- func Int64ToBytes(i int64) []byte
- func NextSequence() interface{}
- type BucketSource
- type Criterion
- type DecodeFunc
- type EncodeFunc
- type Index
- type Operator
- type Options
- type Query
- type QueryType
- type SliceIndex
- type Store
- func (s *Store) Bolt() *bolt.DB
- func (s *Store) Close() error
- func (s *Store) Count(dataType interface{}, query *Query) (int, error)
- func (s *Store) Delete(key, dataType interface{}) error
- func (s *Store) DeleteMatching(dataType interface{}, query *Query) error
- func (s *Store) Find(result interface{}, query *Query) error
- func (s *Store) FindOne(result interface{}, query *Query) error
- func (s *Store) Get(key, result interface{}) error
- func (s *Store) IndexExists(source BucketSource, typeName, indexName string) bool
- func (s *Store) Insert(key, data interface{}) error
- func (s *Store) ReIndex(exampleType interface{}, bucketName []byte) error
- func (s *Store) RemoveIndex(dataType interface{}, indexName string) error
- func (s *Store) TxCount(tx *bolt.Tx, dataType interface{}, query *Query) (int, error)
- func (s *Store) TxDelete(tx *bolt.Tx, key, dataType interface{}) error
- func (s *Store) TxDeleteMatching(tx *bolt.Tx, dataType interface{}, query *Query) error
- func (s *Store) TxFind(tx *bolt.Tx, result interface{}, query *Query) error
- func (s *Store) TxFindOne(tx *bolt.Tx, result interface{}, query *Query) error
- func (s *Store) TxGet(tx *bolt.Tx, key, result interface{}) error
- func (s *Store) TxInsert(tx *bolt.Tx, key, data interface{}) error
- func (s *Store) TxUpdate(tx *bolt.Tx, key interface{}, data interface{}) error
- func (s *Store) TxUpdateMatching(tx *bolt.Tx, dataType interface{}, query *Query, ...) error
- func (s *Store) TxUpsert(tx *bolt.Tx, key interface{}, data interface{}) error
- func (s *Store) Update(key interface{}, data interface{}) error
- func (s *Store) UpdateMatching(dataType interface{}, query *Query, update func(record interface{}) error) error
- func (s *Store) Upsert(key interface{}, data interface{}) error
- type Storer
Constants ¶
const BoltholdIndexTag = "boltholdIndex"
BoltholdIndexTag is the struct tag used to define a field as indexable for a bolthold
const BoltholdKeyTag = "boltholdKey"
BoltholdKeyTag is the struct tag used to define an a field as a key for use in a Find query
const BoltholdUniqueTag = "boltholdUnique"
BoltholdUniqueTag is the struct tag used to define a field as unique constraint
const Key = ""
Key is shorthand for specifying a query to run again the Key in a bolthold, simply returns "" Where(bolthold.Key).Eq("testkey")
Variables ¶
var ErrKeyExists = errors.New("This Key already exists in this bolthold for this type")
ErrKeyExists is the error returned when data is being Inserted for a Key that already exists
var ErrNotFound = errors.New("No data found for this key")
ErrNotFound is returned when no data is found for the given key
var ErrUniqueExists = errors.New("This value cannot be written due to the unique constraint on the field")
ErrUniqueExists is the error thrown when data is being inserted for a unique constraint value that already exists
Functions ¶
func ByteToFloat32 ¶
func ByteToFloat64 ¶
func BytesToInt64 ¶
func DefaultDecode ¶
DefaultDecode is the default decoding func for bolthold (Gob)
func DefaultEncode ¶
DefaultEncode is the default encoding func for bolthold (Gob)
func Float32ToByte ¶
func Float64ToByte ¶
func Int64ToBytes ¶
func NextSequence ¶
func NextSequence() interface{}
NextSequence is used to create a sequential key for inserts Inserts a uint64 as the key store.Insert(bolthold.NextSequence(), data)
Types ¶
type BucketSource ¶
type BucketSource interface { Bucket(name []byte) *bolt.Bucket CreateBucketIfNotExists(name []byte) (*bolt.Bucket, error) }
BucketSource is the source of a bucket for running a query or updating data Buckets and Transactions both implement BucketSource. This allows for choosing a specific bucket or transaction when running a query
type DecodeFunc ¶
DecodeFunc is a function for decoding a value from bytes
type EncodeFunc ¶
EncodeFunc is a function for encoding a value into bytes
type Options ¶
type Options struct { Encoder EncodeFunc Decoder DecodeFunc *bolt.Options }
Options allows you set different options from the defaults For example the encoding and decoding funcs which default to Gob
type SliceIndex ¶
SliceIndex is a function that returns all of the indexable values in a slice
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a bolthold wrapper around a bolt DB
func (*Store) Delete ¶
Delete deletes a record from the bolthold, datatype just needs to be an example of the type stored so that the proper bucket and indexes are updated
func (*Store) DeleteMatching ¶
DeleteMatching deletes all of the records that match the passed in query
func (*Store) Find ¶
Find retrieves a set of values from the bolthold that matches the passed in query result must be a pointer to a slice. The result of the query will be appended to the passed in result slice, rather than the passed in slice being emptied.
func (*Store) FindOne ¶
FindOne returns a single record, and so result is NOT a slice, but an pointer to a struct, if no record is found that matches the query, then it returns ErrNotFound
func (*Store) Get ¶
Get retrieves a value from bolthold and puts it into result. Result must be a pointer
func (*Store) IndexExists ¶
func (s *Store) IndexExists(source BucketSource, typeName, indexName string) bool
IndexExists tests if an index exists for the passed in field name
func (*Store) Insert ¶
Insert inserts the passed in data into the the bolthold
If the the key already exists in the bolthold, then an ErrKeyExists is returned If the data struct has a field tagged as `boltholdKey` and it is the same type as the Insert key, AND the data struct is passed by reference, AND the key field is currently set to the zero-value for that type, then that field will be set to the value of the insert key.
To use this with bolthold.NextSequence() use a type of `uint64` for the key field.
func (*Store) ReIndex ¶
ReIndex removes any existing indexes and adds all the indexes defined by the passed in datatype example This function allows you to index an already existing boltDB file, or refresh any missing indexes if bucketName is nil, then we'll assume a bucketName of storer.Type() if a bucketname is specified, then the data will be copied to the bolthold standard bucket of storer.Type()
func (*Store) RemoveIndex ¶
RemoveIndex removes an index from the store.
func (*Store) TxCount ¶
TxCount returns the current record count from within the given transaction for the passed in datatype
func (*Store) TxDelete ¶
TxDelete is the same as Delete except it allows you specify your own transaction
func (*Store) TxDeleteMatching ¶
TxDeleteMatching does the same as DeleteMatching, but allows you to specify your own transaction
func (*Store) TxFind ¶
TxFind allows you to pass in your own bolt transaction to retrieve a set of values from the bolthold
func (*Store) TxFindOne ¶
TxFindOne allows you to pass in your own bolt transaction to retrieve a single record from the bolthold
func (*Store) TxGet ¶
TxGet allows you to pass in your own bolt transaction to retrieve a value from the bolthold and puts it into result
func (*Store) TxInsert ¶
TxInsert is the same as Insert except it allows you specify your own transaction
func (*Store) TxUpdate ¶
TxUpdate is the same as Update except it allows you to specify your own transaction
func (*Store) TxUpdateMatching ¶
func (s *Store) TxUpdateMatching(tx *bolt.Tx, dataType interface{}, query *Query, update func(record interface{}) error) error
TxUpdateMatching does the same as UpdateMatching, but allows you to specify your own transaction
func (*Store) TxUpsert ¶
TxUpsert is the same as Upsert except it allows you to specify your own transaction
func (*Store) Update ¶
Update updates an existing record in the bolthold if the Key doesn't already exist in the store, then it fails with ErrNotFound
func (*Store) UpdateMatching ¶
func (s *Store) UpdateMatching(dataType interface{}, query *Query, update func(record interface{}) error) error
UpdateMatching runs the update function for every record that match the passed in query Note that the type of record in the update func always has to be a pointer