db

package
v0.0.0-...-ca060dc Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2023 License: GPL-3.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

View Source
const Delimiter = ":::"

Variables

View Source
var EachBreak = errors.New("each break (not an error)")

EachBreak is an error that Each callbacks could return to stop the loop and return nil.

View Source
var ErrKeyNotFound = errors.New("Key not found in database")

Functions

This section is empty.

Types

type Gob

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

func NewGob

func NewGob() *Gob

func (*Gob) Marshal

func (g *Gob) Marshal(v interface{}) ([]byte, error)

func (*Gob) Unmarshal

func (g *Gob) Unmarshal(b []byte, v interface{}) error

type KV

type KV struct {
	Marshalers
	DB *badger.DB
	// contains filtered or unexported fields
}

func KVWithDB

func KVWithDB(db *badger.DB) *KV

func NewKV

func NewKV(opts badger.Options) (*KV, error)

func NewKVFile

func NewKVFile(path string) (*KV, error)

func (*KV) Close

func (kv *KV) Close() error

func (*KV) Node

func (kv *KV) Node(name string) Node

type Log

type Log struct{}

func (*Log) Debugf

func (*Log) Debugf(string, ...interface{})

noop

func (*Log) Errorf

func (*Log) Errorf(f string, v ...interface{})

func (*Log) Infof

func (*Log) Infof(string, ...interface{})

noop

func (*Log) Warningf

func (*Log) Warningf(f string, v ...interface{})

type Marshalers

type Marshalers interface {
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

type Node

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

func (Node) All

func (n Node) All(slicePtr interface{}, prefix string) error

All scans all values with the key prefix into the slice. This method uses reflection.

func (Node) Delete

func (n Node) Delete(k string) error

func (Node) Drop

func (n Node) Drop() error

Drop drops the entire node and all its values.

func (Node) Each

func (n Node) Each(v interface{}, prefix string, fn func(k string) error) error

Each iterates over the bucket all possible keys with the prefix, or no prefix. It takes in a pointer.

Caveats

Since the pointer is reused, the user will need to manually copy it if they want to store the reference to that matched struct. Key includes the prefix.

Example

For iterating, as mentioned above, the user will need to manually copy the pointer by dereferencing and re-referencing it.

var obj  =   &Struct{}
var objs = []*Struct{}

n.Each(obj, "", func(k string) error {
    if obj.Thing == "what I want" {
        cpy := *obj // copy
        objs = append(objs, &cpy)
    }

    return nil
})

func (Node) EachKey

func (n Node) EachKey(prefix string, fn func(k string) error) error

func (Node) Get

func (n Node) Get(k string, v interface{}) error

func (Node) Node

func (n Node) Node(name string) Node

func (Node) Prefix

func (n Node) Prefix() string

Prefix returns the joined prefixes with the trailing delimiter.

func (Node) Set

func (n Node) Set(k string, v interface{}) error

func (Node) SetWithTTL

func (n Node) SetWithTTL(k string, v interface{}, ttl time.Duration) error

Jump to

Keyboard shortcuts

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