db

package
v0.0.0-...-7818d9c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(key string) error

Delete deletes a key from the database

func Find

func Find(prefix string) ([]string, error)

Find retruns all keys that start with the specified prefix

func Get

func Get(key string, valPtr interface{}) error

Get returns the value for the given key

func Init

func Init(conf string) error

Init is a global function initializes the configured database

func IsNotFoudError

func IsNotFoudError(err error) bool

func Set

func Set(key string, val interface{}) error

Set sets the value of the given key

func SetWithTTL

func SetWithTTL(key string, val interface{}, d time.Duration) error

SetWithTTL sets the value of the given key with an time to live (expiration)

Types

type Database

type Database interface {
	Init() error
	Get(string, interface{}) error
	Find(string) ([]string, error)
	Set(string, interface{}) error
	SetWithTTL(string, interface{}, time.Duration) error
	Delete(string) error
}

Database is an interface for a simple key value store intended to be backed by the appropriate database engine for the intended use case ex:

  • redis if running on a server
  • bolt if running in an embeded environment (mobile, drone, ...)
var DB Database

DB holds the global database instance

type FileDB

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

FileDB is a simple bolt based persistent key value store

func NewFileDB

func NewFileDB(path string) *FileDB

NewFileDB creates a FileDB given a path to store data on the filesystem

func (*FileDB) Delete

func (db *FileDB) Delete(key string) error

Delete removes the key from the database

func (*FileDB) Find

func (db *FileDB) Find(prefix string) ([]string, error)

func (*FileDB) Get

func (db *FileDB) Get(key string, valPtr interface{}) error

Get returns the value for the given key

func (*FileDB) Init

func (db *FileDB) Init() error

Init opens the database

func (*FileDB) Set

func (db *FileDB) Set(key string, val interface{}) error

Set sets the value of the given key

func (*FileDB) SetWithTTL

func (db *FileDB) SetWithTTL(key string, val interface{}, d time.Duration) error

SetWithTTL sets the value of the given key with an time to live (expiration)

Jump to

Keyboard shortcuts

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