https://github.com/simia-tech/boltx
Tools for BoltDB https://github.com/boltdb/bolt
https://github.com/simia-tech/boltx
Last synced: 3 months ago
JSON representation
Tools for BoltDB https://github.com/boltdb/bolt
- Host: GitHub
- URL: https://github.com/simia-tech/boltx
- Owner: simia-tech
- License: mit
- Created: 2016-08-02T14:14:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-03-15T11:21:38.000Z (about 8 years ago)
- Last Synced: 2025-01-04T02:48:37.147Z (5 months ago)
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# boltx [](https://travis-ci.org/simia-tech/boltx) [](https://coveralls.io/github/simia-tech/boltx?branch=master) [](https://godoc.org/github.com/simia-tech/boltx) [](https://goreportcard.com/report/github.com/simia-tech/boltx)
This package contains a collection of tools for [BoltDB](https://github.com/boltdb/bolt). 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.```go
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.```go
model := &model{}boltx.PutModel(bucket, []byte("key"), model)
boltx.GetModel(bucket, []byte("key"), model)
```## Queue
The `Queue` helper implements a queue (single-ended) on a bucket. It's persistent and safe to used with
multiple goroutines.```go
queue := boltx.NewQueue(db, []byte("queue-test"))
queue.EnqueueModel(&model{"item"})model := &model{}
queue.DequeueModel(model)log.Println(model)
```## Deque
The `Deque` helper implements a deque (double-ended queue) on a bucket. It's persistent and safe to use with
multiple goroutines.```go
deque := boltx.NewDeque(db, []byte("deque-test"))go func () {
deque.EnqueueModelBack(&model{"item"})
}()model := &model{}
deque.DequeueModelFront(model)log.Println(model)
```