boltdb

package
v0.0.0-...-d5751c4 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DatabaseFileName          = "reporter.db"
	EncryptedDatabaseFileName = "reporter.edb"
)
View Source
const (
	SettingsBucket bucket = iota
)

Variables

This section is empty.

Functions

func AppendFn

func AppendFn[T any](collection *[]T) func(obj interface{}) (interface{}, error)

AppendFn appends elements to the given collection slice

func FilterFn

func FilterFn[T any](collection *[]T, predicate func(T) bool) func(obj interface{}) (interface{}, error)

FilterFn appends elements to the given collection when the predicate is true

func FirstFn

func FirstFn[T any](element *T, predicate func(T) bool) func(obj interface{}) (interface{}, error)

FirstFn sets the element to the first one that satisfies the predicate and stops the computation, returns ErrStop on success

func IsErrObjectNotFound

func IsErrObjectNotFound(e error) bool

Types

type Database

type Database struct {
	*bolt.DB
	// contains filtered or unexported fields
}

func New

func New(logger *log.Logger, options *Options) (*Database, error)

New opens and initializes the BoltDB database.

func (*Database) Close

func (d *Database) Close() error

Close closes the BoltDB database. Safe to being called multiple times.

func (*Database) ConvertToKey

func (d *Database) ConvertToKey(v int) []byte

ConvertToKey returns an 8-byte big endian representation of v. This function is typically used for encoding integer IDs to byte slices so that they can be used as BoltDB keys.

func (*Database) CreateObject

func (d *Database) CreateObject(bucketName string, objFn func(uint64) (int, interface{})) error

CreateObject creates a new object in the bucket, using the next bucket sequence id

func (*Database) CreateObjectWithId

func (d *Database) CreateObjectWithId(bucketName string, id int, obj interface{}) error

CreateObjectWithId creates a new object in the bucket, using the specified id

func (*Database) CreateObjectWithStringId

func (d *Database) CreateObjectWithStringId(bucketName string, id []byte, obj interface{}) error

CreateObjectWithStringId creates a new object in the bucket, using the specified id

func (*Database) DatabaseFileName

func (d *Database) DatabaseFileName() string

DatabaseFileName get the database filename

func (*Database) DeleteAllObjects

func (d *Database) DeleteAllObjects(bucketName string, obj interface{}, matchingFn func(o interface{}) (id int, ok bool)) error

DeleteAllObjects delete all objects where matching() returns (id, ok). TODO: think about how to return the error inside (maybe change ok to type err, and use "notfound"?

func (*Database) DeleteObject

func (d *Database) DeleteObject(bucketName string, key []byte) error

DeleteObject is a generic function used to delete an object inside a database.

func (*Database) GetAll

func (d *Database) GetAll(bucketName string, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error

func (*Database) GetAllWithKeyPrefix

func (d *Database) GetAllWithKeyPrefix(bucketName string, keyPrefix []byte, obj interface{}, appendFn func(o interface{}) (interface{}, error)) error

func (*Database) GetObject

func (d *Database) GetObject(bucketName string, key []byte, object interface{}) error

GetObject is a generic function used to retrieve an unmarshalled object from a database.

func (*Database) MarshalObject

func (d *Database) MarshalObject(object interface{}) ([]byte, error)

MarshalObject encodes an object to binary format

func (*Database) Migrate

func (d *Database) Migrate() error

func (*Database) SetServiceName

func (d *Database) SetServiceName(bucketName string) error

SetServiceName is a generic function used to create a bucket inside a database.

func (*Database) UnmarshalObject

func (d *Database) UnmarshalObject(data []byte, object interface{}) error

UnmarshalObject decodes an object from binary data using the jsoniter library. It is mainly used to accelerate environment(endpoint) decoding at the moment.

func (*Database) UpdateObject

func (d *Database) UpdateObject(bucketName string, key []byte, object interface{}) error

UpdateObject is a generic function used to update an object inside a database.

type Options

type Options struct {
	DataDirectory   string
	EncryptionKey   []byte
	Timeout         int
	InitialMmapSize int
	MaxBatchSize    int
	MaxBatchDelay   int
}

Jump to

Keyboard shortcuts

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