boltutils

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: BSD-3-Clause Imports: 8 Imported by: 4

README

BoltDB utilities

GoDoc

Installation

Run go get resenje.org/boltutils from command line.

Documentation

Index

Constants

View Source
const TimeBytesLen = 9

TimeBytesLen is the length of byte slice time representation returned by TimeToBytesUTC.

Variables

This section is empty.

Functions

func BytesToTimeUTC added in v0.2.2

func BytesToTimeUTC(b []byte) (t time.Time)

BytesToTimeUTC converts slice of bytes as described in TimeToBytesUTC to time.Time.

func DeepBucket added in v0.2.1

func DeepBucket(tx *bolt.Tx, elements ...[]byte) (bucket *bolt.Bucket)

DeepBucket retrieves bucket named as the last element of the elements arguments in nested buckets named as previous elements.

func DeepCreateBucketIfNotExists added in v0.2.1

func DeepCreateBucketIfNotExists(tx *bolt.Tx, elements ...[]byte) (bucket *bolt.Bucket, err error)

DeepCreateBucketIfNotExists creates nested buckets with names of the elements arguments.

func DeepDelete added in v0.2.0

func DeepDelete(tx *bolt.Tx, ensure bool, elements ...[]byte) (err error)

DeepDelete deletes the key named as the last element of the elements arguments in nested buckets named as previous elements. With argument set to true, this function will return ErrNotFound if the element is not deleted.

func DeepDeleteBucket added in v0.2.1

func DeepDeleteBucket(tx *bolt.Tx, ensure bool, elements ...[]byte) (err error)

DeepDeleteBucket deletes bucket named as the last element of the elements arguments in nested buckets named as previous elements. With argument set to true, this function will return ErrNotFound if the element is not deleted.

func DeepGet added in v0.2.0

func DeepGet(tx *bolt.Tx, elements ...[]byte) (data []byte)

DeepGet retrieves the key named as the last element of the elements arguments in nested buckets named as previous elements.

func DeepPut added in v0.2.0

func DeepPut(tx *bolt.Tx, overwrite bool, elements ...[]byte) (new bool, err error)

DeepPut saves the last element of elements arguments under the key named by the second to last element, and all previous elements will be created as buckets if any of them do not exist. With overwrite argument set to false, this function will return ErrExists if the element already exists. Return value new will be true if element is put for the first time.

func IsExistsError added in v0.2.0

func IsExistsError(err error) (yes bool)

IsExistsError returns true if provided error is of ExistsError type.

func IsNotFoundError added in v0.2.0

func IsNotFoundError(err error) (yes bool)

IsNotFoundError returns true if provided error is of NotFoundError type.

func Natural added in v0.4.1

func Natural(in string) (out string)

Natural returns a string suitable for natural sort ordering. All numbers are encoded in big endian binary representation.

func PutTimeToBytesUTC added in v0.2.2

func PutTimeToBytesUTC(b []byte, t time.Time)

PutTimeToBytesUTC puts bytes represention if provided time to provide slice. The slice must have length of 9 bytes.

func TimeToBytesUTC added in v0.2.2

func TimeToBytesUTC(t time.Time) (b []byte)

TimeToBytesUTC returns slice of bytes that represent provided time in UTC. Slice length is always 9, where first 2 bytes represent the year and the rest 7 bytes nanoseconds since the begining the year. This representation is compact, can represent year range from -math.MaxInt16 to math.MaxInt16 and is sortable. Even it is not related to Bolt, it can be used to sort keys by timestamp in a compact representation.

Types

type ExistsError added in v0.2.0

type ExistsError struct {
	Key string
}

ExistsError is retuned by DeepPut if overwrite option is set to false.

func NewExistsError added in v0.2.0

func NewExistsError(key string) *ExistsError

NewExistsError returns a new instance of ExistsError.

func (*ExistsError) Error added in v0.2.0

func (e *ExistsError) Error() string

type NotFoundError added in v0.2.0

type NotFoundError struct {
	Key string
}

NotFoundError is returned by DeepDelete if ensure options is true.

func NewNotFoundError added in v0.2.0

func NewNotFoundError(key string) *NotFoundError

NewNotFoundError returns a new instance of NotFoundError.

func (*NotFoundError) Error added in v0.2.0

func (e *NotFoundError) Error() string

Jump to

Keyboard shortcuts

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