db

package module
v4.0.11 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2023 License: MIT Imports: 13 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 GenerateIndexBaseKey added in v4.0.7

func GenerateIndexBaseKey(model any, field string, val any) string

func GetBucket

func GetBucket(key string) string

func GzipCompress

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

func GzipUncompress

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

func NewModel added in v4.0.9

func NewModel(model any) any

func PaddingZero

func PaddingZero(val any, length int) string

func ParseReflectValue

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

Whether value can be taken directly

func ToBytes

func ToBytes(data any) []byte

func ToEntities added in v4.0.11

func ToEntities[T any](items []any) []T

func ToEntity added in v4.0.11

func ToEntity[T any](val any) T

func ToModelName

func ToModelName(model any) string

func ToSnake added in v4.0.4

func ToSnake(text string) 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

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

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 (txn *Txn) Dec(key string, step int64) (int64, error)

return new value

func (*Txn) Del

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

func (*Txn) Get

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

func (*Txn) Has

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

func (*Txn) Inc

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

return new value

func (*Txn) IndexAdd

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

func (*Txn) IndexClear

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

func (*Txn) IndexCount

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

func (*Txn) IndexDel

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

func (*Txn) IndexFirst

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

func (*Txn) IndexList

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

func (*Txn) IndexModel

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

When isCreate is true, it means to create an index, otherwise it means to delete the index

func (*Txn) List

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

func (*Txn) ModelCounter added in v4.0.9

func (txn *Txn) ModelCounter(model any) (count int64)

func (*Txn) ModelDel added in v4.0.9

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

func (*Txn) ModelGet added in v4.0.9

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

func (*Txn) ModelIdLength added in v4.0.9

func (txn *Txn) ModelIdLength(model any) (length int)

func (*Txn) ModelIndexList added in v4.0.9

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

func (*Txn) ModelList added in v4.0.9

func (txn *Txn) ModelList(model any, limit int, begin string, reverse bool) (list []any, err error)

func (*Txn) ModelNextID added in v4.0.9

func (txn *Txn) ModelNextID(model any, length int) string

func (*Txn) ModelSet added in v4.0.9

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

func (*Txn) ModelTotal added in v4.0.9

func (txn *Txn) ModelTotal(model any) (count int64)

func (*Txn) ModelUnmarshal added in v4.0.10

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

func (*Txn) ModelUpdate added in v4.0.9

func (txn *Txn) ModelUpdate(model, id any, cb func(mPointer any) error) error

func (*Txn) Set

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

func (*Txn) Unmarshal

func (txn *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