storage

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound             = cache.ErrNotFound
	ErrNoKey                = cache.ErrNoKey
	ErrReadOnly             = errors.New("readonly access")
	ErrInvalidBindConfig    = errors.New("invalid bind config")
	ErrMethodIsNotSupported = errors.New("method is not supported")
)
View Source
var (
	ErrStructureOfTheRecordCannotBeReorganized = errors.New("structure of the record cannot be reorganized. All fields with the same prefix must be represented as a key with separator `.` in the key name and have the same size")
	ErrUnsupportedDatatype                     = errors.New("unsupported data type")
	ErrUnsupportedDatetypeConversion           = errors.New("unsupported data type conversion")
)

Functions

This section is empty.

Types

type BindConfig

type BindConfig struct {
	Pattern          string           `json:"pattern" xml:"pattern" yaml:"pattern" toml:"pattern"`
	DBNum            int              `json:"dbnum" xml:"dbnum" yaml:"dbnum" toml:"dbnum"`
	TableName        string           `json:"table_name" xml:"table_name" yaml:"table_name" toml:"table_name"`
	Readonly         bool             `json:"readonly" xml:"readonly" yaml:"readonly" toml:"readonly"`
	WhereExt         string           `json:"where_ext" xml:"where_ext" yaml:"where_ext" toml:"where_ext"`
	GetQuery         string           `json:"get_query" xml:"get_query" yaml:"get_query" toml:"get_query"`
	ListQuery        string           `json:"list_query" xml:"list_query" yaml:"list_query" toml:"list_query"`
	UpsertQuery      string           `json:"upsert_query" xml:"upsert_query" yaml:"upsert_query" toml:"upsert_query"`
	DelQuery         string           `json:"del_query" xml:"del_query" yaml:"del_query" toml:"del_query"`
	ReorganizeNested bool             `json:"reorganize_nested" xml:"reorganize_nested" yaml:"reorganize_nested" toml:"reorganize_nested"`
	DatatypeMapping  []DatatypeMapper `json:"datatype_mapping" xml:"datatype_mapping" yaml:"datatype_mapping" toml:"datatype_mapping"`
}

type CacheSupporter

type CacheSupporter interface {
	SupportCache() bool
}

CacheSupporter extension

type Cacher

type Cacher = cache.Cacher

Cacher manage interface

type DatatypeMapper added in v0.6.0

type DatatypeMapper struct {
	Name string
	Type string
}

type Driver

type Driver interface {
	io.Closer
	Get(ctx context.Context, dbnum int, key string) ([]byte, error)
	Set(ctx context.Context, dbnum int, key string, value []byte) error
	Del(ctx context.Context, dbnum int, key string) error
	Keys(ctx context.Context, dbnum int, pattern string) ([]string, error)
	Bind(ctx context.Context, conf *BindConfig) error
}

Driver storage description

type Record

type Record map[string]any

Record is a map of key-value pairs

func (Record) DatatypeCasting added in v0.7.5

func (r Record) DatatypeCasting(mappers ...DatatypeMapper) (_ Record, err error)

DatatypeCasting convert values to the specified types

func (Record) Get

func (r Record) Get(key string) any

Get value by key

func (Record) ReorganizeNested added in v0.5.0

func (r Record) ReorganizeNested() (Record, error)

ReorganizeNested record according to the key pattern If some fields represented as a key with separator `.` in the key name it need to combine with the other fields with the same prefix Example:

{
	"staff.name": ["George", "John", "Brith"],
	"staff.age": ["20", "21", "22"],
	"staff.gender": ["man", "man", "woman"],
}

After reorganize:

	{
		"staff": [
			{
				"name": "George",
				"age": "20",
			  "gender": "man",
			},
			{
				"name": "John",
				"age": "21",
 		  "gender": "man",
			},
			{
				"name": "Brith",
				"age": "22",
       "gender": "woman",
			},
		],
	}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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