This package contains a collection of tools for BoltDB. It tries to simplify the handling of models in a BoltDB bucket without being too opinionated.
It's basically assumes that models implement encoding.BinaryMarshaler
and encoding.BinaryUnmarshaler
from Go's
standard library.
type model struct { ... }
func (m *model) MarshalBinary() ([]byte, error) { ... }
func (m *model) UnmarshalBinary([]byte) (error) { ... }
Those methods should handle the (de)serialization of the model. The interfaces are than used by the functions of this package to store and load models.
model := &model{}
boltx.PutModel(bucket, []byte("key"), model)
boltx.GetModel(bucket, []byte("key"), model)
The Queue
helper implements a queue (single-ended) on a bucket. It's persistent and safe to used with
multiple goroutines.
queue := boltx.NewQueue(db, []byte("queue-test"))
queue.EnqueueModel(&model{"item"})
model := &model{}
queue.DequeueModel(model)
log.Println(model)
The Deque
helper implements a deque (double-ended queue) on a bucket. It's persistent and safe to use with
multiple goroutines.
deque := boltx.NewDeque(db, []byte("deque-test"))
go func () {
deque.EnqueueModelBack(&model{"item"})
}()
model := &model{}
deque.DequeueModelFront(model)
log.Println(model)