boltutil

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: MIT Imports: 11 Imported by: 0

README

boltutil

GitHub Actions codecov Go Report Card GitHub go.mod Go version GitHub tag (latest by date)

Boltutil implements some utility tools for bolt database.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotExist     = errors.New("not exist")
	ErrAlreadyExist = errors.New("already exist")
)

Functions

This section is empty.

Types

type Coder

type Coder interface {
	Encode(writer io.Writer, v any) error
	Decode(reader io.Reader, v any) error
}

Coder is the interface that can encode and decode data.

type Condition added in v0.2.0

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

func NewCondition added in v0.2.0

func NewCondition() *Condition

func (*Condition) FailIfExist added in v0.2.0

func (c *Condition) FailIfExist(v ...bool) *Condition

func (*Condition) FailIfNotExist added in v0.2.0

func (c *Condition) FailIfNotExist(v ...bool) *Condition

func (*Condition) IgnoreIfExist added in v0.2.0

func (c *Condition) IgnoreIfExist(v ...bool) *Condition

func (*Condition) IgnoreIfNotExist added in v0.2.0

func (c *Condition) IgnoreIfNotExist(v ...bool) *Condition

type DB

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

func Open

func Open(path string, options ...Option) (*DB, error)

Open creates and opens a database with given options.

func Wrap

func Wrap(db *bbolt.DB) *DB

Wrap return a DB with then given bbolt.DB

func (*DB) Close added in v0.2.0

func (d *DB) Close() error

Close closes the database.

func (*DB) Count

func (d *DB) Count(obj Storable, filters ...*Filter) (int, error)

Count return count of kv in the bucket.

func (*DB) Delete

func (d *DB) Delete(obj Storable, conditions ...*Condition) error

Delete deletes storable object.

func (*DB) DeleteAllBucket

func (d *DB) DeleteAllBucket() error

DeleteAllBucket remove all buckets

func (*DB) DeleteBucket

func (d *DB) DeleteBucket(hasBuckets ...HasBucket) error

DeleteBucket remove the specified buckets

func (*DB) Exist added in v0.2.0

func (d *DB) Exist(obj Storable) (bool, error)

Exist check if the storable exist

func (*DB) First added in v0.2.0

func (d *DB) First(obj Storable, filters ...*Filter) error

First injects the first value in the bucket into result.

func (*DB) Get

func (d *DB) Get(obj Storable, conditions ...*Condition) error

Get injects storable object with its key.

func (*DB) MDelete added in v0.2.0

func (d *DB) MDelete(objs ...Storable) error

MDelete remove values by key of storables

func (*DB) MGet added in v0.2.0

func (d *DB) MGet(objs ...Storable) error

MGet injects storable objects with their keys.

func (*DB) MPut added in v0.2.0

func (d *DB) MPut(objs ...Storable) error

MPut store storables into database, create bucket if it does not exist.

func (*DB) Put

func (d *DB) Put(obj Storable, conditions ...*Condition) error

Put stores storable object.

func (*DB) Scan added in v0.2.0

func (d *DB) Scan(result any, filters ...*Filter) error

Scan scans values in the bucket and put them into result.

func (*DB) Unwrap

func (d *DB) Unwrap() *bbolt.DB

Unwrap return the original bbolt.DB

type Filter added in v0.2.0

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

func NewFilter added in v0.2.0

func NewFilter() *Filter

func (*Filter) AddCondition added in v0.2.0

func (c *Filter) AddCondition(f func(k, v []byte) (skip bool, stop bool)) *Filter

func (*Filter) AddStorableCondition added in v0.2.0

func (c *Filter) AddStorableCondition(f func(obj Storable) (skip bool, stop bool)) *Filter

func (*Filter) SetPrefix added in v0.2.0

func (c *Filter) SetPrefix(prefix []byte) *Filter

func (*Filter) SetRange added in v0.2.0

func (c *Filter) SetRange(min, max []byte) *Filter

type GobCoder

type GobCoder struct {
}

GobCoder implements Coder with gob

func (GobCoder) Decode

func (c GobCoder) Decode(reader io.Reader, v any) error

func (GobCoder) Encode

func (c GobCoder) Encode(writer io.Writer, v any) error

type HasBeforePut added in v0.2.0

type HasBeforePut interface {
	BeforePut(id uint64) // will be called before put, id is an auto incrementing integer for the bucket
}

HasBeforePut is the interface that indicates the BeforePut method

type HasBucket

type HasBucket interface {
	BoltBucket() []byte
}

HasBucket is the interface that indicates the bound bucket

type HasCoder

type HasCoder interface {
	BoltCoder() Coder
}

HasCoder is the interface that indicates the Coder of the type

type JsonCoder

type JsonCoder struct {
	Intent bool
}

JsonCoder implements Coder with json

func (JsonCoder) Decode

func (c JsonCoder) Decode(reader io.Reader, v any) error

func (JsonCoder) Encode

func (c JsonCoder) Encode(writer io.Writer, v any) error

type Option

type Option func(options *innerOption)

Option represents the options that can be set when opening a database.

func WithDefaultCoder

func WithDefaultCoder(defaultCoder Coder) Option

WithDefaultCoder return Option with specified DefaultCoder

func WithFileMode

func WithFileMode(fileMode os.FileMode) Option

WithFileMode return Option with specified FileMode

func WithFreelistType

func WithFreelistType(freelistType bbolt.FreelistType) Option

WithFreelistType return Option with specified FreelistType

func WithInitialMmapSize

func WithInitialMmapSize(initialMmapSize int) Option

WithInitialMmapSize return Option with specified InitialMmapSize

func WithMmapFlags

func WithMmapFlags(mmapFlags int) Option

WithMmapFlags return Option with specified MmapFlags

func WithNoFreelistSync

func WithNoFreelistSync(noFreelistSync bool) Option

WithNoFreelistSync return Option with specified NoFreelistSync

func WithNoGrowSync

func WithNoGrowSync(noGrowSync bool) Option

WithNoGrowSync return Option with specified NoGrowSync

func WithNoSync

func WithNoSync(noSync bool) Option

WithNoSync return Option with specified NoSync

func WithOpenFile

func WithOpenFile(openFile func(string, int, os.FileMode) (*os.File, error)) Option

WithOpenFile return Option with specified OpenFile,

func WithPageSize

func WithPageSize(pageSize int) Option

WithPageSize return Option with specified PageSize

func WithReadOnly

func WithReadOnly(readOnly bool) Option

WithReadOnly return Option with specified ReadOnly

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout return Option with specified Timeout

type Storable

type Storable interface {
	HasBucket
	BoltKey() []byte
}

Storable is the interface that can be stored into bolt.

type XmlCoder

type XmlCoder struct {
}

XmlCoder implements Coder with xml

func (XmlCoder) Decode

func (c XmlCoder) Decode(reader io.Reader, v any) error

func (XmlCoder) Encode

func (c XmlCoder) Encode(writer io.Writer, v any) error

Jump to

Keyboard shortcuts

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