Documentation ¶
Overview ¶
package db implements Bolt based database which can be encrypted on the fly and which supports automatic backups. It offers very simple API and hides all the complex stuff behind it. It's thread safe. More information see the Cfg struct.
Index ¶
- Constants
- Variables
- func AddKeyValueToBucket(bucket []byte, keyValue, index *Data) (err error)
- func Backup() (did bool, err error)
- func BackupTicker(interval time.Duration) (done chan<- struct{})
- func Close() (err error)
- func GetAllValuesFromBucket(bucket []byte, transforms ...Filter) (values [][]byte, err error)
- func GetKeyValueFromBucket(bucket []byte, index, keyValue *Data) (found bool, err error)
- func GracefulStop()
- func Init(cfg Cfg) (err error)
- func RmKeyValueFromBucket(bucket []byte, index *Data) (err error)
- func Wipe() (err error)
- type Cfg
- type Data
- type Filter
- type Handle
- type Mgd
- func (db *Mgd) AddKeyValueToBucket(bucket []byte, keyValue, index *Data) (err error)
- func (db *Mgd) Backup() (did bool, err error)
- func (db *Mgd) BackupTicker(interval time.Duration) (done chan<- struct{})
- func (db *Mgd) Close() (err error)
- func (db *Mgd) GetAllValuesFromBucket(bucket []byte, transforms ...Filter) (values [][]byte, err error)
- func (db *Mgd) GetKeyValueFromBucket(bucket []byte, index, keyValue *Data) (found bool, err error)
- func (db *Mgd) RmKeyValueFromBucket(bucket []byte, index *Data) (err error)
- func (db *Mgd) SetStatusFn(f OnFn)
- func (db *Mgd) Wipe() (err error)
- type OnFn
- type Use
Constants ¶
const MEM_PREFIX = "MEMORY_"
Variables ¶
var ErrDisabledDB = errors.New("database is turned off")
Functions ¶
func AddKeyValueToBucket ¶
AddKeyValueToBucket add value to bucket pointed by the index. keyValue and index use Data type's operators to encrypt and hash data on the fly.
func Backup ¶
Backup takes backup copy of the database. Before backup the database is closed automatically and only dirty databases are backed up.
func BackupTicker ¶
BackupTicker creates a backup ticker which takes backup copy of the database file specified by the interval. Ticker can be stopped with returned done channel.
func Close ¶
func Close() (err error)
Close closes the database. It can be used after that if wanted. Transactions opens the database when needed.
func GetAllValuesFromBucket ¶ added in v0.1.31
GetAllValuesFromBucket returns all entries from the bucket. Note: - Order is not guaranteed. - The returned slice contains only the values as byte arrays. Keys are excluded. Transform functions can be used e.g. to decrypt the data. They are applied in the provided order. Errors will return only if it cannot perform the transaction successfully.
func GetKeyValueFromBucket ¶
GetKeyValueFromBucket writes keyValue data by the index from a bucket. It returns `found` if key value exists. Errors will return only if it cannot perform the transaction successfully.
func GracefulStop ¶ added in v0.2.25
func GracefulStop()
GracefulStop closes all database instances immediately.
func Init ¶
Init initializes managed version of the encrypted database. Database is ready to use after this call. See more information of Cfg struct.
func RmKeyValueFromBucket ¶ added in v0.1.21
RmKeyValueFromBucket removes value pointed by the index from the bucket. The index uses Data type's operators to encrypt and hash data on the fly.
Types ¶
type Cfg ¶
type Cfg struct { // Filename is full path file name of the DB file. Note, if the base // of the filename starts with MEM_PREFIX, the memory database is created. // That's useful e.g. testing and profiling. Filename string // Base part of the backup file names. Date and time is added. BackupName string // Buckets is slice of the bucket names that are in byte slice. Buckets [][]byte }
Cfg is configuration needed to create and open managed database that is implemented with Bolt DB or by memory maps for testing and profiling. See Filename for more information.
type Data ¶
Data is general data element for encrypted database. It offers placeholders for read, write, and use operators to over write.
type Handle ¶ added in v0.1.47
type Handle interface { AddKeyValueToBucket(bucket []byte, keyValue, index *Data) (err error) RmKeyValueFromBucket(bucket []byte, index *Data) (err error) GetKeyValueFromBucket(bucket []byte, index, keyValue *Data) (found bool, err error) GetAllValuesFromBucket(bucket []byte, transforms ...Filter) (values [][]byte, err error) BackupTicker(interval time.Duration) (done chan<- struct{}) Backup() (did bool, err error) Wipe() (err error) Close() (err error) SetStatusFn(f OnFn) }
func New ¶ added in v0.1.21
New creates a new managed and encrypted database. This is a preferred way to use the managed database package. There is also the alternated Init function when you don't need to store the Mgd instance by yourself. It's for the cases when only one managed database is needed per a process or an application. Database is ready to use after this call. You don't need to open it and backup can be taken during the run. See more information of Cfg struct.
type Mgd ¶
type Mgd struct { Cfg // contains filtered or unexported fields }
Mgd is a managed and encrypted (option, can be pre-procession as well) DB.
func (*Mgd) AddKeyValueToBucket ¶ added in v0.1.21
AddKeyValueToBucket add value to bucket pointed by the index. keyValue and index use Data type's operators to encrypt and hash data on the fly.
func (*Mgd) Backup ¶ added in v0.1.21
Backup takes backup copy of the database. Before backup the database is closed automatically and only dirty databases are backed up.
func (*Mgd) BackupTicker ¶ added in v0.1.21
BackupTicker creates a backup ticker which takes backup copy of the database file specified by the interval. Ticker can be stopped with returned done channel.
func (*Mgd) Close ¶ added in v0.1.21
Close closes the database. It can be used after that if wanted. Transactions opens the database when needed.
func (*Mgd) GetAllValuesFromBucket ¶ added in v0.1.31
func (db *Mgd) GetAllValuesFromBucket( bucket []byte, transforms ...Filter, ) ( values [][]byte, err error, )
GetAllValuesFromBucket returns all entries from the bucket. Note: - Order is not guaranteed. - The returned slice contains only the values as byte arrays. Keys are excluded. Transform functions can be used e.g. to decrypt the data. They are applied in the provided order. Errors will return only if it cannot perform the transaction successfully.
func (*Mgd) GetKeyValueFromBucket ¶ added in v0.1.21
func (db *Mgd) GetKeyValueFromBucket( bucket []byte, index, keyValue *Data, ) ( found bool, err error, )
GetKeyValueFromBucket writes keyValue data by the index from a bucket. It returns `found` if key value exists. Errors will return only if it cannot perform the transaction successfully.
func (*Mgd) RmKeyValueFromBucket ¶ added in v0.1.21
RmKeyValueFromBucket removes value pointed by the index from the bucket. The index uses Data type's operators to encrypt and hash data on the fly.