Skip to content

alchemy/boom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages