db

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package db provides functionalities related to data storage. This includes caching as well as persistence storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDelete

func CacheDelete(db BucketName, key string) error

CacheDelete deletes a given key from the given cache bucket returning a error indicating the success.

func CacheGet

func CacheGet(db BucketName, key string) ([]byte, error)

CacheGet returns the value for a given key from the given cache bucket and a error indicating the success.

func CacheGetRenewExpire

func CacheGetRenewExpire(db BucketName, key string, expiration time.Duration) ([]byte, error)

CacheGetRenewExpire returns the value for a given key from the given cache bucket and a error indicating the success. It also sets the time to life for the given key to the given expiration time after which the value cannot be retrieved anymore.

func CacheSet

func CacheSet(db BucketName, key string, value interface{}) error

CacheSet sets the value for a given key in the given cache bucket returning a error indicating the success.

func CacheSetWithExpire

func CacheSetWithExpire(db BucketName, key string, value interface{}, expiration time.Duration) error

CacheSetWithExpire sets the value for a given key in the given cache bucket returning a error indicating the success. The Value will expire after the given time after which it cannot be retrieved anymore.

func CacheTruncate

func CacheTruncate(db BucketName) error

CacheTruncate truncates given cache bucket returning a error indicating the success. After truncating the cache bucket will not hold any keys.

func CacheTruncateSoon

func CacheTruncateSoon(db BucketName) error

CacheTruncateSoon truncates given cache bucket returning a error indicating the success. After truncating the cache bucket will not hold any keys. CacheTruncateSoon does not truncate immediately and only once in a given time span

func CacheWipeAll

func CacheWipeAll() error

CacheWipeAll wipes all data from the cache returning a error indicating the success.

func Delete

func Delete(db BucketName, key string) error

Delete deletes a given key from the given persistent bucket returning a error indicating the success.

func Get

func Get(db BucketName, key string) ([]byte, error)

Get returns the value for a given key from the given persistent bucket and a error indicating the success.

func GetRenewExpire

func GetRenewExpire(db BucketName, key string, expiration time.Duration) ([]byte, error)

GetRenewExpire returns the value for a given key from the given persistent bucket and a error indicating the success. It also sets the time to life for the given key to the given expiration time after which the value cannot be retrieved anymore.

func InitAsBadgerDB

func InitAsBadgerDB()

InitAsBadgerDB initializes the cache and persistence KeyValueDB variables with BadgerDBs.

func LoadConfig

func LoadConfig(data []byte)

LoadConfig loads the database config from the given config data

func NewNotFoundError

func NewNotFoundError(msg string) error

NewNotFoundError creates a new NotFoundError with the given message.

func Set

func Set(db BucketName, key string, value interface{}) error

Set sets the value for a given key in the given persistent bucket returning a error indicating the success.

func SetWithExpire

func SetWithExpire(db BucketName, key string, value interface{}, expiration time.Duration) error

SetWithExpire sets the value for a given key in the given persistent bucket returning a error indicating the success. The Value will expire after the given time after which it cannot be retrieved anymore.

func Transact

func Transact(transaction func(*badger.Txn) error) error

Transact makes a transaction for the data db.

func TransactRead

func TransactRead(txn *badger.Txn, db BucketName, key string, v *[]byte) error

TransactRead applies read changes in a transaction

func TransactWrite

func TransactWrite(txn *badger.Txn, db BucketName, key string, value interface{}, expiration time.Duration) error

TransactWrite applies write changes in a transaction

func View

func View(transaction func(*badger.Txn) error) error

View makes a read only transaction for the data db.

Types

type BucketName

type BucketName int

BucketName is an type aliases used to differentiate different tables / buckets

const (
	CACHEStates BucketName = iota
	CACHEClientConfigs
	CACHEFlowInfo
	CACHEDynamicFeatures
	CACHEDevicePollingResults

	CACHEHelpPages
	CACHEHContents
	CACHEMailActivation
)

BucketNames for the cache

const (
	DBFlowInfoShare BucketName = iota
	DBCommunityFeatures
	DBPersonalCompareViewSpecs
	DBNotifications
	DBNotificationFields
	DBNotificationProviders
	DBNotificationFeatures
)

BucketNames for persistence storage

type KeyValueDB

type KeyValueDB interface {
	Get(db BucketName, key string) ([]byte, error)
	GetRenewExpire(db BucketName, key string, expiration time.Duration) ([]byte, error)
	Set(db BucketName, key string, value interface{}) error
	SetWithExpire(db BucketName, key string, value interface{}, expiration time.Duration) error
	Delete(db BucketName, key string) error
	Truncate(db BucketName) error
	TruncateSoon(db BucketName) error
	Transact(func(*badger.Txn) error) error
	View(func(txn *badger.Txn) error) error
	Read(txn *badger.Txn, db BucketName, key string, v *[]byte) error
	Write(txn *badger.Txn, db BucketName, key string, value interface{}, expiration time.Duration) (err error)
}

KeyValueDB is an interface for a Key Value storage

type NotFoundError

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

NotFoundError is an error type used when a key is not found.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Jump to

Keyboard shortcuts

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