db

package
v0.1.35 Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: Apache-2.0 Imports: 7 Imported by: 5

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

This section is empty.

Variables

This section is empty.

Functions

func AddKeyValueToBucket

func AddKeyValueToBucket(bucket []byte, keyValue, index *Data) (err error)

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

func Backup() (did bool, err error)

Backup takes backup copy of the database. Before backup the database is closed automatically and only dirty databases are backed up.

func BackupTicker

func BackupTicker(interval time.Duration) (done chan<- struct{})

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

func 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 GetKeyValueFromBucket

func 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 Init

func Init(cfg Cfg) (err error)

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

func RmKeyValueFromBucket(bucket []byte, index *Data) (err error)

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.

func Wipe

func Wipe() (err error)

Wipe removes the whole database and its master file.

Types

type Cfg

type Cfg struct {
	Filename   string   // Filename is full path file name of the DB file
	BackupName string   // Base part of the backup file names. Date and time is added.
	Buckets    [][]byte // Buckets is list of the buckets needed
}

Cfg is configuration needed to create and open managed database.

type Data

type Data struct {
	Data  []byte
	Read  Filter
	Write Filter
	Use
	Result interface{}
}

Data is general data element for encrypted database. It offers placeholders for read, write, and use operators to over write.

type Filter

type Filter func(value []byte) (k []byte)

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 New added in v0.1.21

func New(cfg Cfg) *Mgd

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.

func (*Mgd) AddKeyValueToBucket added in v0.1.21

func (db *Mgd) AddKeyValueToBucket(bucket []byte, keyValue, index *Data) (err error)

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

func (db *Mgd) Backup() (did bool, err error)

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

func (db *Mgd) BackupTicker(interval time.Duration) (done chan<- struct{})

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

func (db *Mgd) Close() (err error)

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

func (db *Mgd) RmKeyValueFromBucket(bucket []byte, index *Data) (err error)

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.

func (*Mgd) Wipe added in v0.1.21

func (db *Mgd) Wipe() (err error)

Wipe removes the whole database and its master file.

type Use

type Use func(value []byte) interface{}

Jump to

Keyboard shortcuts

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