kvdb

package
v0.0.0-...-48f0ced Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2021 License: MIT Imports: 5 Imported by: 10

Documentation

Index

Constants

View Source
const (
	//FeatureStore key-value database store(Set/Get/Delete) feature
	FeatureStore = Feature(1 << iota)
	//FeatureTTLStore key-value database ttl store(SetWithTTL/Get/Delete) feature
	FeatureTTLStore
	//FeatureExpiredStore key-value database expired store(SetWithExpired/Get/Delete) feature
	FeatureExpiredStore
	//FeatureCounter key-value database counter(SetCounter/IncreaseCounter/GetCounter/DeleteCounter) feature
	FeatureCounter
	//FeatureTTLCounter key-value database counter(SetCounterWithTTL/IncreaseCounterWithTTL/GetCounter/DeleteCounter) feature
	FeatureTTLCounter
	//FeatureNext key-value database next (Next) feature
	FeatureNext
	//FeaturePrev key-value database prev (Prev) feature
	FeaturePrev
	//FeatureInsert key-value database insert (Insert) feature
	FeatureInsert
	//FeatureTTLInsert key-value database ttl insert (InsertWithTTL) feature
	FeatureTTLInsert
	//FeatureUpdate key-value database update (Update) feature
	FeatureUpdate
	//FeatureTTLUpdate key-value database ttl update (UpdateWithTTL) feature
	FeatureTTLUpdate
	//FeatureTransaction key-value database transactio(Begin) feature
	FeatureTransaction
	//FeatureNonpersistent  if data will be drop after application restart
	FeatureNonpersistent
	//FeatureUnstable if data may be droped if needed.
	FeatureUnstable
	//FeatureEmbedded if database is embedded.
	FeatureEmbedded
)
View Source
const (
	//IsolationLevelBatch isolation-level batch.Batch insert data,get data in transaction will return data in databse directly.
	IsolationLevelBatch = IsolationLevel(1 << iota)
	//IsolationLevelReadUncommitted isolation-level read uncommitted
	IsolationLevelReadUncommitted
	//IsolationLevelReadCommitted isolation-level read committed
	IsolationLevelReadCommitted
	//IsolationLevelRepeatableRead isolation-level repeatable read
	IsolationLevelRepeatableRead
	//IsolationLevelSerializable isolation-level serializable
	IsolationLevelSerializable
)
View Source
const FeaturesSetEmpty = Feature(0)

FeaturesSetEmpty empty feature set

Variables

View Source
var ErrFeatureNotSupported = errors.New("feature not supported")

ErrFeatureNotSupported error raised if given feature is not supported

View Source
var ErrFeatureSupported = errors.New("feature supported")

ErrFeatureSupported error raised if given feature is supported

View Source
var ErrUnsupportedNextLimit = errors.New("unsuported next limit")

ErrUnsupportedNextLimit error raised when next limit unsupported

View Source
var Passthrough = &passthrough{}

Passthrough key value database which do not store any data

View Source
var SuggestedCounterPrefix = []byte{1}

SuggestedCounterPrefix suggest key prefix for counter/ttlcounter feature

View Source
var SuggestedDataPrefix = []byte{0}

SuggestedDataPrefix suggest key prefix for store/ttlstore feature

Functions

func Apply

func Apply(db *Database, driver string, loader func(interface{}) error) error

func Factories

func Factories() []string

Factories returns a sorted list of the names of the registered factories.

func Register

func Register(name string, f Factory)

Register makes a driver creator available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.

func UnregisterAll

func UnregisterAll()

UnregisterAll unregister all driver

Types

type Config

type Config struct {
	Driver string
	Config func(v interface{}) error `config:", lazyload"`
}

func (*Config) ApplyTo

func (c *Config) ApplyTo(db *Database) error

type Database

type Database struct {
	Driver
}

Database key-value database struct

func New

func New() *Database

New create new database

func (*Database) ShouldNotSupport

func (d *Database) ShouldNotSupport(features Feature) error

ShouldNotSupport return ErrFeatureSupported if any given feature be supported by driver

func (*Database) ShouldSupport

func (d *Database) ShouldSupport(features Feature) error

ShouldSupport return ErrFeatureNotSupported if any given feature not be supported by driver

type Driver

type Driver interface {
	//Start start database
	Start() error
	//Stop stop database
	Stop() error
	//Set set value by given key
	Set(key []byte, value []byte) error
	//Get get value by given key
	Get(key []byte) ([]byte, error)
	//Delete delete value by given key
	Delete(key []byte) error
	//Next return keys after iter not more than given limit
	//Empty iter (nil or 0 length []byte) will start a new search
	//Return keyvalue ,newiter and any error if raised.
	//Empty iter (nil or 0 length []byte) will be returned if no more keys
	Next(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error)
	//Prev return keys before iter not more than given limit
	//Empty iter (nil or 0 length []byte) will start a new search
	//Return keys ,newiter and any error if raised.
	//Empty iter (nil or 0 length []byte) will be returned if no more keys
	Prev(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error)
	//SetWithTTL set value by given key and ttl in second.
	SetWithTTL(key []byte, value []byte, ttlInSecond int64) error
	//SetWithExpired set value by given key and expired timestamp.
	SetWithExpired(key []byte, value []byte, expired int64) error
	//Begin begin new transaction
	Begin() (Transaction, error)
	//Insert insert value with given key.
	//Insert will fail if data with given key exists.
	//Return if operation success and any error if raised
	Insert(Key []byte, value []byte) (bool, error)
	//InsertWithTTL insert value with given key and ttl in second.
	//Insert will fail if data with given key exists.
	//Return if operation success and any error if raised
	InsertWithTTL(Key []byte, value []byte, ttlInSecond int64) (bool, error)
	//Update update value with given key.
	//Update will fail if data with given key does nto exist.
	//Return if operation success and any error if raised
	Update(key []byte, value []byte) (bool, error)
	//UpdateWithTTL update value with given key and ttl in second.
	//Update will fail if data with given key does nto exist.
	//Return if operation success and any error if raised
	UpdateWithTTL(key []byte, value []byte, ttlInSecond int64) (bool, error)
	//SetCounter set counter value with given key
	SetCounter(key []byte, value int64) error
	//SetCounterWithTTL set counter value with given key and ttl
	SetCounterWithTTL(key []byte, value int64, ttlInSecond int64) error
	//IncreaseCounter increace counter value with given key and increasement.
	//Value not existed coutn as 0.
	//Return final value and any error if raised.
	IncreaseCounter(key []byte, incr int64) (int64, error)
	//IncreaseCounterWithTTL increace counter value with given key ,increasement,and ttl.
	//Value not existed coutn as 0.
	//Return final value and any error if raised.
	IncreaseCounterWithTTL(key []byte, incr int64, ttlInSecond int64) (int64, error)
	//GetCounter get counter value with given key
	//Value not existed coutn as 0.
	GetCounter(key []byte) (int64, error)
	//DeleteCounter delete counter value with given key
	DeleteCounter(key []byte) error
	//Features return supported features
	Features() Feature
	//IsolationLevel transaction isolation level
	//Return 0 if transaction is not supported
	IsolationLevel() IsolationLevel
	//SetErrorHanlder set error hanlder
	SetErrorHanlder(func(error))
}

Driver key value database driver interface

func NewDriver

func NewDriver(name string, loader func(v interface{}) error) (Driver, error)

NewDriver create new driver with given name loader. Reutrn driver created and any error if raised.

func PassthroughFactory

func PassthroughFactory(loader func(v interface{}) error) (Driver, error)

PassthroughFactory passthrough driver factory

type Factory

type Factory func(loader func(v interface{}) error) (Driver, error)

Factory keyvalue database driver create factory.

type Feature

type Feature int64

Feature key-value database feature type

func (Feature) SupportAll

func (f Feature) SupportAll(dst Feature) bool

SupportAll check if all given features are supported

func (Feature) SupportAny

func (f Feature) SupportAny(dst Feature) bool

SupportAny check if any one of given features are supported

type IsolationLevel

type IsolationLevel int64

IsolationLevel transaction isolation level

type Nop

type Nop struct{}

Nop key-value database driver All method except "Close" will raise an ErrFeatureNotSupported error. All key-value database driver should implement Nop driver

func (Nop) Begin

func (n Nop) Begin() (Transaction, error)

Begin begin new transaction

func (Nop) Delete

func (n Nop) Delete(key []byte) error

Delete delete value by given key

func (Nop) DeleteCounter

func (n Nop) DeleteCounter(key []byte) error

DeleteCounter delete counter value with given key

func (Nop) Features

func (n Nop) Features() Feature

Features return supported features

func (Nop) Get

func (n Nop) Get(key []byte) ([]byte, error)

Get get value by given key

func (Nop) GetCounter

func (n Nop) GetCounter(key []byte) (int64, error)

GetCounter get counter value with given key Value not existed coutn as 0.

func (Nop) IncreaseCounter

func (n Nop) IncreaseCounter(key []byte, incr int64) (int64, error)

IncreaseCounter increace counter value with given key and increasement. Value not existed coutn as 0. Return final value and any error if raised.

func (Nop) IncreaseCounterWithTTL

func (n Nop) IncreaseCounterWithTTL(key []byte, incr int64, ttlInSecond int64) (int64, error)

IncreaseCounterWithTTL increace counter value with given key ,increasement,and ttl in second Value not existed coutn as 0. Return final value and any error if raised.

func (Nop) Insert

func (n Nop) Insert(Key []byte, value []byte) (bool, error)

Insert insert value with given key. Insert will fail if data with given key exists. Return if operation success and any error if raised

func (Nop) InsertWithTTL

func (n Nop) InsertWithTTL(Key []byte, value []byte, ttlInSecond int64) (bool, error)

InsertWithTTL insert value with given key and ttl in second. Insert will fail if data with given key exists. Return if operation success and any error if raised

func (Nop) IsolationLevel

func (n Nop) IsolationLevel() IsolationLevel

IsolationLevel transaction isolation level

func (Nop) Next

func (n Nop) Next(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error)

Next return values after key not more than given limit

func (Nop) Prev

func (n Nop) Prev(iter []byte, limit int) (kv []*herbdata.KeyValue, newiter []byte, err error)

Prev return values after key not more than given limit

func (Nop) Set

func (n Nop) Set(key []byte, value []byte) error

Set set value by given key

func (Nop) SetCounter

func (n Nop) SetCounter(key []byte, value int64) error

SetCounter set counter value with given key

func (Nop) SetCounterWithTTL

func (n Nop) SetCounterWithTTL(key []byte, value int64, ttlInSecond int64) error

SetCounterWithTTL set counter value with given key and ttl in second

func (Nop) SetErrorHanlder

func (n Nop) SetErrorHanlder(func(error))

SetErrorHanlder set error hanlder

func (Nop) SetWithExpired

func (n Nop) SetWithExpired(key []byte, value []byte, expired int64) error

SetWithExpired set value by given key and expired timestamp.

func (Nop) SetWithTTL

func (n Nop) SetWithTTL(key []byte, value []byte, ttlInSecond int64) error

SetWithTTL set value by given key and ttl in second

func (Nop) Start

func (n Nop) Start() error

Start start database

func (Nop) Stop

func (n Nop) Stop() error

Stop stop database

func (Nop) Update

func (n Nop) Update(key []byte, value []byte) (bool, error)

Update update value with given key. Update will fail if data with given key does nto exist. Return if operation success and any error if raised

func (Nop) UpdateWithTTL

func (n Nop) UpdateWithTTL(key []byte, value []byte, ttlInSecond int64) (bool, error)

UpdateWithTTL update value with given key and ttl in second. Update will fail if data with given key does nto exist. Return if operation success and any error if raised

type Transaction

type Transaction interface {
	//Rollback rollback transaction.
	//Discard all operations in transaction.
	Rollback() error
	//Commit commit transaction
	//Apply all operaions in transaction.
	Commit() error
	//Set set value by given key
	Set(key []byte, value []byte) error
	//Get get value by given key
	Get(key []byte) ([]byte, error)
	//Delete delete value by given key
	Delete(key []byte) error
	//SetWithTTL set value by given key and ttl in Second
	SetWithTTL(key []byte, value []byte, ttlInSecond int64) error
	//IsolationLevel transaction isolation level
	IsolationLevel() IsolationLevel
}

Transaction datanase transaction interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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