boom

package module
v0.0.0-...-cc48cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2022 License: MIT Imports: 7 Imported by: 0

README

boom - BbOlt Object Mapper

Experimental package to make it easier to persist go structs in a bbolt key/value store using generics.

Example:

import (
    "log"

    bolt "go.etcd.io/bbolt"
    "github.com/alchemy/boom"
)

const dbName "bbolt.db"

func main() {
    db, err := bolt.Open(dbName, 0600, nil)
    if err != nil {
        log.Fatal(err)
    }
    defer db.Close()
    customer := &Customer{BaseDataObj: BaseDataObj{Id: 1}, CompanyName: "ACME Labs"}
    dao := boom.NewDao[Customer]()
    err = db.Update(func(tx *bolt.Tx) error {
        dao.CreateBucketIfNotExists(tx)
        return dao.Put(tx, customer)
    })
    if err != nil {
        log.Fatal(err)
    }
    var value *Customer
    err = db.View(func(tx *bolt.Tx) error {
        value, err = dao.Get(tx, customer.Key())
        return err
    })
    if err != nil {
        log.Fatal(err)
    }
    log.Println(value)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GobDecode

func GobDecode(b []byte, e interface{}) error

func GobEncode

func GobEncode(e interface{}) ([]byte, error)

Types

type BaseDataObj

type BaseDataObj struct {
	Id uint64
}

func (BaseDataObj) Key

func (bdo BaseDataObj) Key() []byte

func (BaseDataObj) Name

func (bdo BaseDataObj) Name() []byte

type Dao

type Dao[T DataDescriptor] struct {
	BucketName []byte
	// contains filtered or unexported fields
}

func NewDao

func NewDao[T DataDescriptor]() *Dao[T]

func (*Dao[T]) Bucket

func (dao *Dao[T]) Bucket(tx *bolt.Tx) *bolt.Bucket

func (*Dao[T]) CreateBucketIfNotExists

func (dao *Dao[T]) CreateBucketIfNotExists(tx *bolt.Tx) (*bolt.Bucket, error)

func (*Dao[T]) Decode

func (dao *Dao[T]) Decode(data []byte) (*T, error)

func (*Dao[T]) Delete

func (dao *Dao[T]) Delete(tx *bolt.Tx, key []byte) error

func (*Dao[T]) Encode

func (dao *Dao[T]) Encode(value *T) ([]byte, error)

func (*Dao[T]) First

func (dao *Dao[T]) First(tx *bolt.Tx) (*T, error)

func (*Dao[T]) Get

func (dao *Dao[T]) Get(tx *bolt.Tx, key []byte) (*T, error)

func (*Dao[T]) GetBy

func (dao *Dao[T]) GetBy(tx *bolt.Tx, idxName string, idxValue interface{}) ([]*T, error)

func (*Dao[T]) Last

func (dao *Dao[T]) Last(tx *bolt.Tx) (*T, error)

func (*Dao[T]) Next

func (dao *Dao[T]) Next(tx *bolt.Tx) (*T, error)

func (*Dao[T]) Prev

func (dao *Dao[T]) Prev(tx *bolt.Tx) (*T, error)

func (*Dao[T]) Put

func (dao *Dao[T]) Put(tx *bolt.Tx, obj *T) error

type DataDescriptor

type DataDescriptor interface {
	Name() []byte
	Key() []byte
}

type IndexDescription

type IndexDescription struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL