Documentation ¶
Index ¶
- Variables
- func AutoIncrement() func(*DB) error
- func BoltOptions(mode os.FileMode, options *bolt.Options) func(*DB) error
- func Codec(c codec.EncodeDecoder) func(*DB) error
- func Limit(limit int) func(q *queryOptions)
- func Root(root ...string) func(*DB) error
- func Skip(offset int) func(q *queryOptions)
- type DB
- func (s *DB) All(to interface{}, options ...func(*queryOptions)) error
- func (s *DB) AllByIndex(fieldName string, to interface{}, options ...func(*queryOptions)) error
- func (s *DB) Begin(writable bool) (*Node, error)
- func (s *DB) Close() error
- func (s *DB) Commit() error
- func (s *DB) Delete(bucketName string, key interface{}) error
- func (s *DB) Drop(bucketName string) error
- func (s *DB) Find(fieldName string, value interface{}, to interface{}, ...) error
- func (s *DB) From(root ...string) *Node
- func (s *DB) Get(bucketName string, key interface{}, to interface{}) error
- func (s *DB) Init(data interface{}) error
- func (s *DB) One(fieldName string, value interface{}, to interface{}) error
- func (s *DB) Range(fieldName string, min, max, to interface{}, options ...func(*queryOptions)) error
- func (s *DB) Remove(data interface{}) error
- func (s *DB) Rollback() error
- func (s *DB) Save(data interface{}) error
- func (s *DB) Set(bucketName string, key interface{}, value interface{}) error
- func (s *DB) WithTransaction(tx *bolt.Tx) *Node
- type Index
- type ListIndex
- func (idx *ListIndex) Add(value []byte, targetID []byte) error
- func (idx *ListIndex) All(value []byte, opts *queryOptions) ([][]byte, error)
- func (idx *ListIndex) AllRecords(opts *queryOptions) ([][]byte, error)
- func (idx *ListIndex) Get(value []byte) []byte
- func (idx *ListIndex) Range(min []byte, max []byte, opts *queryOptions) ([][]byte, error)
- func (idx *ListIndex) Remove(value []byte) error
- func (idx *ListIndex) RemoveID(targetID []byte) error
- type Node
- func (n *Node) All(to interface{}, options ...func(*queryOptions)) error
- func (n *Node) AllByIndex(fieldName string, to interface{}, options ...func(*queryOptions)) error
- func (n Node) Begin(writable bool) (*Node, error)
- func (n *Node) Commit() error
- func (n *Node) CreateBucketIfNotExists(tx *bolt.Tx, bucket string) (*bolt.Bucket, error)
- func (n *Node) Delete(bucketName string, key interface{}) error
- func (n *Node) Drop(bucketName string) error
- func (n *Node) Find(fieldName string, value interface{}, to interface{}, ...) error
- func (n Node) From(addend ...string) *Node
- func (n *Node) Get(bucketName string, key interface{}, to interface{}) error
- func (n *Node) GetBucket(tx *bolt.Tx, children ...string) *bolt.Bucket
- func (n *Node) Init(data interface{}) error
- func (n *Node) One(fieldName string, value interface{}, to interface{}) error
- func (n *Node) Range(fieldName string, min, max, to interface{}, options ...func(*queryOptions)) error
- func (n *Node) Remove(data interface{}) error
- func (n *Node) Rollback() error
- func (n *Node) Save(data interface{}) error
- func (n *Node) Set(bucketName string, key interface{}, value interface{}) error
- func (n Node) WithTransaction(tx *bolt.Tx) *Node
- type UniqueIndex
- func (idx *UniqueIndex) Add(value []byte, targetID []byte) error
- func (idx *UniqueIndex) All(value []byte, opts *queryOptions) ([][]byte, error)
- func (idx *UniqueIndex) AllRecords(opts *queryOptions) ([][]byte, error)
- func (idx *UniqueIndex) Get(value []byte) []byte
- func (idx *UniqueIndex) Range(min []byte, max []byte, opts *queryOptions) ([][]byte, error)
- func (idx *UniqueIndex) Remove(value []byte) error
- func (idx *UniqueIndex) RemoveID(id []byte) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoID is returned when no ID field or id tag is found in the struct. ErrNoID = errors.New("missing struct tag id or ID field") // ErrZeroID is returned when the ID field is a zero value. ErrZeroID = errors.New("id field must not be a zero value") // ErrBadType is returned when a method receives an unexpected value type. ErrBadType = errors.New("provided data must be a struct or a pointer to struct") // ErrAlreadyExists is returned uses when trying to set an existing value on a field that has a unique index. ErrAlreadyExists = errors.New("already exists") // ErrNilParam is returned when the specified param is expected to be not nil. ErrNilParam = errors.New("param must not be nil") // ErrUnknownTag is returned when an unexpected tag is specified. ErrUnknownTag = errors.New("unknown tag") // ErrIdxNotFound is returned when the specified index is not found. ErrIdxNotFound = errors.New("index not found") // ErrSlicePtrNeeded is returned when an unexpected value is given, instead of a pointer to slice. ErrSlicePtrNeeded = errors.New("provided target must be a pointer to slice") // ErrSlicePtrNeeded is returned when an unexpected value is given, instead of a pointer to struct. ErrStructPtrNeeded = errors.New("provided target must be a pointer to struct") // ErrSlicePtrNeeded is returned when an unexpected value is given, instead of a pointer. ErrPtrNeeded = errors.New("provided target must be a pointer to a valid variable") // ErrNoName is returned when the specified struct has no name. ErrNoName = errors.New("provided target must have a name") // ErrNotFound is returned when the specified record is not saved in the bucket. ErrNotFound = errors.New("not found") // ErrNotInTransaction is returned when trying to rollback or commit when not in transaction. ErrNotInTransaction = errors.New("not in transaction") )
Errors
Functions ¶
func AutoIncrement ¶
AutoIncrement used to enable bolt.NextSequence on empty integer ids.
func BoltOptions ¶
BoltOptions used to pass options to BoltDB.
func Codec ¶
func Codec(c codec.EncodeDecoder) func(*DB) error
Codec used to set a custom encoder and decoder. The default is GOB.
func Limit ¶
func Limit(limit int) func(q *queryOptions)
Limit sets the maximum number of records to return
Types ¶
type DB ¶
type DB struct { // Path of the database file Path string // Handles encoding and decoding of objects Codec codec.EncodeDecoder // Bolt is still easily accessible Bolt *bolt.DB // contains filtered or unexported fields }
DB is the wrapper around BoltDB. It contains an instance of BoltDB and uses it to perform all the needed operations
func OpenWithOptions ¶
func OpenWithOptions(path string, mode os.FileMode, boltOptions *bolt.Options, stormOptions ...func(*DB)) (*DB, error)
OpenWithOptions opens a database with the given boltDB options and optional Storm options. Deprecated: Use storm.Open with storm.BoltOptions instead.
func (*DB) AllByIndex ¶
AllByIndex gets all the records of a bucket that are indexed in the specified index
func (*DB) Find ¶
func (s *DB) Find(fieldName string, value interface{}, to interface{}, options ...func(q *queryOptions)) error
Find returns one or more records by the specified index
func (*DB) From ¶
From returns a new Storm node with a new bucket root. All DB operations on the new node will be executed relative to the given bucket.
func (*DB) Range ¶
func (s *DB) Range(fieldName string, min, max, to interface{}, options ...func(*queryOptions)) error
Range returns one or more records by the specified index within the specified range
type Index ¶
type Index interface { Add(value []byte, targetID []byte) error Remove(value []byte) error RemoveID(id []byte) error Get(value []byte) []byte All(value []byte, opts *queryOptions) ([][]byte, error) AllRecords(opts *queryOptions) ([][]byte, error) Range(min []byte, max []byte, opts *queryOptions) ([][]byte, error) }
Index interface
type ListIndex ¶
type ListIndex struct { Parent *bolt.Bucket IndexBucket *bolt.Bucket IDs *UniqueIndex }
ListIndex is an index that references values and the corresponding IDs.
func NewListIndex ¶
NewListIndex loads a ListIndex
func (*ListIndex) AllRecords ¶
AllRecords returns all the IDs of this index
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
A Node in Storm represents the API to a BoltDB bucket.
func (*Node) AllByIndex ¶
AllByIndex gets all the records of a bucket that are indexed in the specified index
func (*Node) CreateBucketIfNotExists ¶
CreateBucketIfNotExists creates the bucket below the current node if it doesn't already exist.
func (*Node) Find ¶
func (n *Node) Find(fieldName string, value interface{}, to interface{}, options ...func(q *queryOptions)) error
Find returns one or more records by the specified index
func (Node) From ¶
From returns a new Storm node with a new bucket root below the current. All DB operations on the new node will be executed relative to this bucket.
func (*Node) Range ¶
func (n *Node) Range(fieldName string, min, max, to interface{}, options ...func(*queryOptions)) error
Range returns one or more records by the specified index within the specified range
type UniqueIndex ¶
UniqueIndex is an index that references unique values and the corresponding ID.
func NewUniqueIndex ¶
func NewUniqueIndex(parent *bolt.Bucket, indexName []byte) (*UniqueIndex, error)
NewUniqueIndex loads a UniqueIndex
func (*UniqueIndex) Add ¶
func (idx *UniqueIndex) Add(value []byte, targetID []byte) error
Add a value to the unique index
func (*UniqueIndex) All ¶
func (idx *UniqueIndex) All(value []byte, opts *queryOptions) ([][]byte, error)
All returns all the ids corresponding to the given value
func (*UniqueIndex) AllRecords ¶
func (idx *UniqueIndex) AllRecords(opts *queryOptions) ([][]byte, error)
AllRecords returns all the IDs of this index
func (*UniqueIndex) Get ¶
func (idx *UniqueIndex) Get(value []byte) []byte
Get the id corresponding to the given value
func (*UniqueIndex) Range ¶
func (idx *UniqueIndex) Range(min []byte, max []byte, opts *queryOptions) ([][]byte, error)
Range returns the ids corresponding to the given range of values
func (*UniqueIndex) Remove ¶
func (idx *UniqueIndex) Remove(value []byte) error
Remove a value from the unique index
func (*UniqueIndex) RemoveID ¶
func (idx *UniqueIndex) RemoveID(id []byte) error
RemoveID removes an ID from the unique index