ezbunt

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2020 License: MIT Imports: 6 Imported by: 0

README

ezbunt

ezbunt is a Go module for conveniently interacting with a buntdb. Functions include: creating a data file, storing simple data types, and complex types as JSON objects.

Documentation

godoc.org/github.com/racecarparts/ezbunt

Usage

via: go.mod (go module):

require (
    ...
    github.com/racecarparts/ezbunt v0.1.2
)

or via: go get

$ go get -u github.com/racecarparts/ezbunt

Example

package main

import (
    "fmt"
    ez "github.com/racecarparts/ezbunt"
)

func main() {
    ez := ez.New("data.file")
    ez.WriteKeyVal("my:1234", "sharona")

    pairs, err := ez.GetPairs("my")
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(pairs)

    val, err := ez.GetVal("my:1234")
    if err != nil {
        fmt.Println(err)
    }
    fmt.Println(val)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ezbunt

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

Ezbunt encapsulates and extends a buntdb instance

func New added in v0.1.2

func New(dbFilePath string) *Ezbunt

New creates and returns an Ezbunt with a new buntdb (with a backing file at the path provided)

func (*Ezbunt) DeleteKey

func (ez *Ezbunt) DeleteKey(key string) (string, error)

DeleteKey removes a key-value pair and returns the value of the removed key

func (*Ezbunt) GetPairs

func (ez *Ezbunt) GetPairs(keyPrefix string) (map[string]string, error)

GetPairs retrieves a map of key-value pairs based on a key prefix

func (*Ezbunt) GetVal

func (ez *Ezbunt) GetVal(key string) (string, error)

GetVal retrieves the value, and possible error, for the corresponding key.

func (*Ezbunt) GetValAsBool added in v0.1.1

func (ez *Ezbunt) GetValAsBool(key string) (bool, error)

GetValAsBool retrieves the value as a `bool` type, and possible error, for the corresponding key.

func (*Ezbunt) GetValAsBoolDefault added in v0.1.1

func (ez *Ezbunt) GetValAsBoolDefault(key string, defaultVal bool) bool

GetValAsBoolDefault retrieves the value for the corresponding key. If the key is not found, the value is not found, or an error is returned from the db, the provided default is returned.

func (*Ezbunt) GetValAsBytes

func (ez *Ezbunt) GetValAsBytes(key string) ([]byte, error)

GetValAsBytes retrieves the value as []byte, and possible error, for the corresponding key. Useful for retrieving JSON objects.

func (*Ezbunt) GetValAsInt added in v0.1.1

func (ez *Ezbunt) GetValAsInt(key string) (int, error)

GetValAsInt retrieves the value as an `int` type, and possible error, for the corresponding key.

func (*Ezbunt) GetValAsIntDefault added in v0.1.1

func (ez *Ezbunt) GetValAsIntDefault(key string, defaultVal int) int

GetValAsIntDefault retrieves the value for the corresponding key. If the key is not found, the value is not found, or an error is returned from the db, the provided default is returned.

func (*Ezbunt) GetValAsTime added in v0.1.3

func (ez *Ezbunt) GetValAsTime(key string) (time.Time, error)

GetValAsTime retrieves the value as a `time.Time` type, and possible error, for the corresponding key.

func (*Ezbunt) GetValAsTimeDefault added in v0.1.3

func (ez *Ezbunt) GetValAsTimeDefault(key string, defaultVal time.Time) time.Time

GetValAsTimeDefault retrieves the value for the corresponding key. If the key is not found, the value is not found, or an error is returned from the db, the provided default is returned.

func (*Ezbunt) GetValDefault

func (ez *Ezbunt) GetValDefault(key string, defaultVal string) string

GetValDefault retrieves the value for the corresponding key. If the key is not found, the value is not found, or an error is returned from the db, the provided default is returned.

func (*Ezbunt) WriteKeyVal

func (ez *Ezbunt) WriteKeyVal(key string, val string) error

WriteKeyVal persists a key-value string pair indefinitley

func (*Ezbunt) WriteKeyValAsBool

func (ez *Ezbunt) WriteKeyValAsBool(key string, val bool) error

WriteKeyValAsBool persists a key-value string/bool pair indefinitley

func (*Ezbunt) WriteKeyValAsBoolTTL

func (ez *Ezbunt) WriteKeyValAsBoolTTL(key string, val bool, ttlSeconds int) error

WriteKeyValAsBoolTTL persists a key-value string/bool pair with a TTL in seconds

func (*Ezbunt) WriteKeyValAsInt

func (ez *Ezbunt) WriteKeyValAsInt(key string, val int) error

WriteKeyValAsInt persists a key-value string/int pair indefinitley

func (*Ezbunt) WriteKeyValAsIntTTL

func (ez *Ezbunt) WriteKeyValAsIntTTL(key string, val int, ttlSeconds int) error

WriteKeyValAsIntTTL persists a key-value string/int pair with a TTL in seconds

func (*Ezbunt) WriteKeyValAsJSON

func (ez *Ezbunt) WriteKeyValAsJSON(key string, val interface{}) error

WriteKeyValAsJSON persists a key-value pair with a string key, and converts the val to a json []byte, and stores it as the value. Useful for complex types.

func (*Ezbunt) WriteKeyValAsJSONTTL

func (ez *Ezbunt) WriteKeyValAsJSONTTL(key string, val interface{}, ttlSeconds int) error

WriteKeyValAsJSONTTL persists a key-value pair with a string key, and converts the val to a json []byte, and stores it as the value, with a TTL in seconds. Useful for complex types.

func (*Ezbunt) WriteKeyValAsTime added in v0.1.3

func (ez *Ezbunt) WriteKeyValAsTime(key string, val time.Time) error

WriteKeyValAsTime persists a key-value string/time.Time pair indefinitley

func (*Ezbunt) WriteKeyValAsTimeTTL added in v0.1.3

func (ez *Ezbunt) WriteKeyValAsTimeTTL(key string, val time.Time, ttlSeconds int) error

WriteKeyValAsTimeTTL persists a key-value string/time.Time pair with a TTL in seconds

func (*Ezbunt) WriteKeyValTTL

func (ez *Ezbunt) WriteKeyValTTL(key string, val string, ttlSeconds int) error

WriteKeyValTTL persists a key-value string pair with a ttl in seconds

Jump to

Keyboard shortcuts

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