db

package module
v3.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 11 Imported by: 0

README

db

a key-value file system database

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("key not found")
)

Functions

func GzipCompress

func GzipCompress(src []byte) ([]byte, error)

func GzipUncompress

func GzipUncompress(src []byte) ([]byte, error)

func PaddingZero added in v3.1.4

func PaddingZero(val any, length int) string

func ParseReflectValue added in v3.2.0

func ParseReflectValue(val reflect.Value) (any, bool)

Whether value can be taken directly

func ToBytes

func ToBytes(data any) []byte

func ToModelName added in v3.2.0

func ToModelName(model any) string

Types

type DB

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

func New

func New(dir string, readOnly bool) (*DB, error)

or set env: DATABASE_DIR

func (*DB) Close

func (t *DB) Close()

func (*DB) List added in v3.1.1

func (t *DB) List(prefix string, fn func(key string, value []byte) (stop bool, err error), options ...*ListOption) error

func (*DB) Txn

func (t *DB) Txn(fn func(txn *Txn) error, readOnly ...bool) error

type ListOption added in v3.1.1

type ListOption struct {
	Begin        string // The starting key, not included by default
	ContainBegin bool   // The result contains the key of begin
	Reverse      bool   // Iterate from back to front
	Limit        int    // The maximum number of iterations
	KeyOnly      bool   // Only iterate over keys
}

type Txn

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

func (*Txn) Dec

func (t *Txn) Dec(key string, step int64) (int64, error)

return new value

func (*Txn) Del

func (t *Txn) Del(key string) error

func (*Txn) Get

func (t *Txn) Get(key string) ([]byte, error)

func (*Txn) Has

func (t *Txn) Has(key string) bool

func (*Txn) Inc

func (t *Txn) Inc(key string, step int64) (int64, error)

return new value

func (*Txn) IndexAdd added in v3.1.6

func (txn *Txn) IndexAdd(model any, field string, val, id any) error

func (*Txn) IndexClear added in v3.1.6

func (txn *Txn) IndexClear(model any, field string, val any) error

func (*Txn) IndexCount added in v3.1.6

func (txn *Txn) IndexCount(model any, field string, val any) (total int64)

func (*Txn) IndexDel added in v3.1.6

func (txn *Txn) IndexDel(model any, field string, val, id any) error

func (*Txn) IndexFirst added in v3.2.0

func (txn *Txn) IndexFirst(model any, field string, val any) (string, error)

func (*Txn) IndexList added in v3.1.6

func (txn *Txn) IndexList(model any, field string, val any, opts ...*ListOption) (list []string, err error)

func (*Txn) IndexModel added in v3.2.0

func (txn *Txn) IndexModel(id, model any) error

func (*Txn) List

func (t *Txn) List(prefix string, fn func(key string, value []byte) (stop bool, err error), options ...*ListOption) error

func (*Txn) Set

func (t *Txn) Set(key string, value any) error

func (*Txn) Unmarshal

func (t *Txn) Unmarshal(key string, value any) error

Jump to

Keyboard shortcuts

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