Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/simia-tech/boltx

Tools for BoltDB https://github.com/boltdb/bolt
https://github.com/simia-tech/boltx

Last synced: 6 days ago
JSON representation

Tools for BoltDB https://github.com/boltdb/bolt

Awesome Lists containing this project

README

        

# boltx [![Build Status](https://travis-ci.org/simia-tech/boltx.svg?branch=master)](https://travis-ci.org/simia-tech/boltx) [![Coverage Status](https://coveralls.io/repos/github/simia-tech/boltx/badge.svg?branch=master)](https://coveralls.io/github/simia-tech/boltx?branch=master) [![GoDoc](https://godoc.org/github.com/simia-tech/boltx?status.svg)](https://godoc.org/github.com/simia-tech/boltx) [![Go Report Card](https://goreportcard.com/badge/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)
```