badger

package
v0.0.0-...-67d7764 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2018 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

package badger implements database operations for BadgerDB

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a wrapper with reference to underlying Badger database and implements BlockstackDB operations

func New

func New(path string) (*DB, error)

New attempts to create a new Badger database instance given path.

func (*DB) Get

func (db *DB) Get(key []byte) (result []byte, err error)

Get attempts to return value at given key. If an error occurs, it is returned and the result will be an empty byte slice.

func (*DB) GetNames

func (db *DB) GetNames() (map[string]map[string]bool, error)

GetNames returns the set of all names at current day

func (*DB) GetNamesAt

func (db *DB) GetNamesAt(t time.Time) (result map[string]map[string]bool, err error)

GetNamesAt returns set of names across all namespaces at a given day. The time parameter is used as the key, rounded to start of day in UTC format, and converted to Unix epoch time. The result is map[NamespaceName][SetOfNames], using a boolean map for the name set since Go does not have builtin sets. The set of names are stored as gzip compressed bytes, and are uncompressed when retrieved from database.

func (*DB) Put

func (db *DB) Put(key, value []byte) error

Put attempts to insert a key value pair, and returns an error if any occur

func (*DB) PutNames

func (db *DB) PutNames(names map[string]map[string]bool) error

PutNames inserts the set of names for each namespace into the database where the key is the current date rounded to start of day.

func (*DB) PutNamesAt

func (db *DB) PutNamesAt(names map[string]map[string]bool, t time.Time) error

TODO insert the names per namespace as well, otherwise would always need to grab all names PutNamesAt attempts to insert the set of names for each namespace into the database using the given time as key, rounded to start of day in UTC and converted to Unix epoch time. The set of names are stored as gzip compressed bytes, and are uncompressed when retrieved from database.

func (*DB) Shutdown

func (db *DB) Shutdown() error

Shutdown closes the database. It is critical to call this before closing the application in order ensure persistence of all data by flushing to disk.

Jump to

Keyboard shortcuts

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