data

package
v0.0.0-...-bbd0b33 Latest Latest
Warning

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

Go to latest
Published: May 20, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EntryIDDateSeparator is used for separating date from the rest
	EntryIDDateSeparator = "_"
	// ErrReadPrefixText is used as prefix text for read errors
	ErrReadPrefixText = "Following errors occurred while reading the entries:"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerDB

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

BadgerDB represents a Badger database

func GetBadgerDB

func GetBadgerDB(location string, dbUtils BadgerDBUtils) (*BadgerDB, error)

GetBadgerDB returns a reference to BadgerDB struct

func (BadgerDB) Close

func (b BadgerDB) Close() error

Close closes connection to database

func (BadgerDB) GetDate

func (b BadgerDB) GetDate(entry Entry) string

GetDate extracts date from the given entry

func (BadgerDB) GetKey

func (b BadgerDB) GetKey(entry Entry) string

GetKey returns key of the entry

func (BadgerDB) Read

func (b BadgerDB) Read(id string) (Entry, error)

Read retrives entry with given id from the database

func (BadgerDB) ReadIDList

func (b BadgerDB) ReadIDList(date string) ([]string, error)

ReadIDList retrieves list of IDs matching the given date

func (BadgerDB) ReadList

func (b BadgerDB) ReadList(date string) ([]Entry, error)

ReadList returns list of entries matching the given date

func (BadgerDB) Write

func (b BadgerDB) Write(entry Entry) error

Write writes given entry to database

func (BadgerDB) WriteList

func (b BadgerDB) WriteList(entry Entry) error

WriteList writes given entry into matching list of entries

type BadgerDBUtils

type BadgerDBUtils interface {
	Encode(Entry) ([]byte, error)
	Decode([]byte) (Entry, error)
	EncodeList([]Entry) ([]byte, error)
	DecodeList([]byte) ([]Entry, error)
}

BadgerDBUtils represents functions required for calling DB functions

type BadgerDBUtilsDefault

type BadgerDBUtilsDefault struct{}

BadgerDBUtilsDefault represents default implementation of BadgerDBUtils

func (BadgerDBUtilsDefault) Decode

func (b BadgerDBUtilsDefault) Decode(value []byte) (Entry, error)

Decode returns entry after decoding the given value

func (BadgerDBUtilsDefault) DecodeList

func (b BadgerDBUtilsDefault) DecodeList(value []byte) ([]Entry, error)

DecodeList returns entry after decoding the given value

func (BadgerDBUtilsDefault) Encode

func (b BadgerDBUtilsDefault) Encode(entry Entry) ([]byte, error)

Encode returns encoded value of the given entry

func (BadgerDBUtilsDefault) EncodeList

func (b BadgerDBUtilsDefault) EncodeList(entryList []Entry) ([]byte, error)

EncodeList returns encoded value of the given entry list

type DB

type DB interface {
	Write(entry Entry) error
	WriteList(entry Entry) error
	Read(id string) (Entry, error)
	ReadList(date string) ([]Entry, error)
}

DB represents a database

type Entry

type Entry struct {
	ID       string
	AppName  string
	Duration time.Duration
}

Entry represents a database entry

Jump to

Keyboard shortcuts

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