Need help with stow?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

djherbis
131 Stars 9 Forks MIT License 86 Commits 0 Opened issues

Description

Simple object persistence with boltdb

Services available

!
?

Need anything else?

Contributors list

# 188,497
Shell
Jupyter...
asynchr...
tokio
71 commits
# 346,108
Go
Shell
Kuberne...
k8s-sta...
2 commits
# 88,785
golang
rabbitm...
linq
snake-g...
1 commit
# 32,381
avatar-...
golang
Vue.js
webasse...
1 commit

Stow

GoDoc Release Software License Build Status Coverage Status Go Report Card

Usage

This package provides a persistence manager for objects backed by bbolt (orig. boltdb).

package main

import ( "encoding/gob" "fmt" "log"

bolt "go.etcd.io/bbolt" "gopkg.in/djherbis/stow.v3" )

func main() { // Create a boltdb (bbolt fork) database db, err := bolt.Open("my.db", 0600, nil) if err != nil { log.Fatal(err) }

// Open/Create a Json-encoded Store, Xml and Gob are also built-in // We'll store a greeting and person in a boltdb bucket named "people" peopleStore := stow.NewJSONStore(db, []byte("people"))

peopleStore.Put("hello", Person{Name: "Dustin"})

peopleStore.ForEach(func(greeting string, person Person) { fmt.Println(greeting, person.Name) })

// Open/Create a Gob-encoded Store. The Gob encoding keeps type information, // so you can encode/decode interfaces! sayerStore := stow.NewStore(db, []byte("greetings"))

var sayer Sayer = Person{Name: "Dustin"} sayerStore.Put("hello", &sayer)

var retSayer Sayer sayerStore.Get("hello", &retSayer) retSayer.Say("hello")

sayerStore.ForEach(func(sayer Sayer) { sayer.Say("hey") }) }

type Sayer interface { Say(something string) }

type Person struct { Name string }

func (p Person) Say(greeting string) { fmt.Printf("%s says %s.\n", p.Name, greeting) }

func init() { gob.Register(&Person{}) }

Installation

go get gopkg.in/djherbis/stow.v3

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.