database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2018 License: LGPL-3.0 Imports: 16 Imported by: 20

Documentation

Overview

Package database is a generated GoMock package.

Index

Constants

View Source
const (
	IntPrefix       = "i"
	StringPrefix    = "s"
	NilPrefix       = "n"
	BoolPrefix      = "b"
	JSONPrefix      = "j"
	MapHolderPrefix = "@"
)

const prefixs

View Source
const BasicPrefix = "b-"

BasicPrefix prefix of basic types

View Source
const (
	// CoinPrefix ...
	CoinPrefix = "o-"
)
View Source
const ContractPrefix = "c-"

ContractPrefix ...

View Source
const (
	// IOSTPrefix prefix of iost
	IOSTPrefix = "i-"
)
View Source
const MapPrefix = "m-"

MapPrefix prefix of map key

View Source
const Separator = "-"

Separator separator of map key

View Source
const (
	// StateTable name
	StateTable = "state"
)

Variables

This section is empty.

Functions

func LoadBlockhead

func LoadBlockhead(path string) (*block.BlockHead, error)

LoadBlockhead load block info as block.BlockHead from json file

func LoadTxInfo

func LoadTxInfo(path string) (*tx.Tx, error)

LoadTxInfo load tx info as tx.Tx from json file

func Marshal

func Marshal(in interface{}) (string, error)

Marshal marshal go types to value string

func MustMarshal

func MustMarshal(in interface{}) string

MustMarshal marshal go types to value string, panic on error

func MustUnmarshal

func MustUnmarshal(o string) interface{}

MustUnmarshal unmarshal value string to go types, panic on error

func Unmarshal

func Unmarshal(o string) interface{}

Unmarshal unmarshal value string to go types

Types

type BalanceHandler

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

BalanceHandler handler of balace storage

func (*BalanceHandler) Balance

func (m *BalanceHandler) Balance(name string) int64

Balance get balance to id

func (*BalanceHandler) Servi

func (m *BalanceHandler) Servi(name string) int64

Servi get servi of name, return 0 if not exists

func (*BalanceHandler) SetBalance

func (m *BalanceHandler) SetBalance(to string, delta int64)

SetBalance set balance to id

func (*BalanceHandler) SetServi

func (m *BalanceHandler) SetServi(to string, delta int64)

SetServi add delta to servi of to

func (*BalanceHandler) TotalServi

func (m *BalanceHandler) TotalServi() int64

TotalServi get total servi of name, return 0 if not exists

type BasicHandler

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

BasicHandler handler of basic type

func (*BasicHandler) Del

func (m *BasicHandler) Del(key string)

Del del key, if key is nil do nothing

func (*BasicHandler) Get

func (m *BasicHandler) Get(key string) (value string)

Get get v from k

func (*BasicHandler) Has

func (m *BasicHandler) Has(key string) bool

Has determine if k exist

func (*BasicHandler) Put

func (m *BasicHandler) Put(key, value string)

Put put to k-v

type CoinHandler

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

CoinHandler handler of coin

func (*CoinHandler) Coin

func (m *CoinHandler) Coin(coinName string, name string) int64

Coin get balance of coin

func (*CoinHandler) SetCoin

func (m *CoinHandler) SetCoin(coinName string, to string, delta int64)

SetCoin set specified coins to id

type ContractHandler

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

ContractHandler ...

func (*ContractHandler) Contract

func (m *ContractHandler) Contract(key string) (c *contract.Contract)

Contract get contract by key

func (*ContractHandler) DelContract

func (m *ContractHandler) DelContract(key string)

DelContract delete contract, if contract not exist, do nothing

func (*ContractHandler) HasContract

func (m *ContractHandler) HasContract(key string) bool

HasContract determine if contract existed

func (*ContractHandler) SetContract

func (m *ContractHandler) SetContract(contract *contract.Contract)

SetContract set contract to storage, will not do check

type IMultiValue

type IMultiValue interface {
	Get(table string, key string) (string, error)
	Put(table string, key string, value string) error
	Del(table string, key string) error
	Has(table string, key string) (bool, error)
	Keys(table string, prefix string) ([]string, error)
	Commit()
	Rollback()
}

IMultiValue mvcc database interface

type LRU

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

LRU lru cache

func NewLRU

func NewLRU(length int, db database) *LRU

NewLRU make a new lru

func (*LRU) Del

func (m *LRU) Del(key string)

Del delete key from cache

func (*LRU) Get

func (m *LRU) Get(key string) (value string)

Get get from cache

func (*LRU) Has

func (m *LRU) Has(key string) bool

Has if key exist

func (*LRU) Keys

func (m *LRU) Keys(prefix string) []string

Keys list keys under prefix, do nothing

func (*LRU) Purge

func (m *LRU) Purge()

Purge delete all keys

func (*LRU) Put

func (m *LRU) Put(key, value string)

Put put kv to cache

type MapHandler

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

MapHandler handler of map

func (*MapHandler) MDel

func (m *MapHandler) MDel(key, field string)

MDel delete field of map o(1)

func (*MapHandler) MGet

func (m *MapHandler) MGet(key, field string) (value string)

MGet get value from storage o(1)

func (*MapHandler) MHas

func (m *MapHandler) MHas(key, field string) bool

MHas if has map and field

func (*MapHandler) MKeys

func (m *MapHandler) MKeys(key string) (fields []string)

MKeys list fields of map o(1)

func (*MapHandler) MPut

func (m *MapHandler) MPut(key, field, value string)

MPut put value in kfv storage o(1)

type MockIMultiValue

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

MockIMultiValue is a mock of IMultiValue interface

func NewMockIMultiValue

func NewMockIMultiValue(ctrl *gomock.Controller) *MockIMultiValue

NewMockIMultiValue creates a new mock instance

func (*MockIMultiValue) Commit

func (m *MockIMultiValue) Commit()

Commit mocks base method

func (*MockIMultiValue) Del

func (m *MockIMultiValue) Del(arg0, arg1 string) error

Del mocks base method

func (*MockIMultiValue) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockIMultiValue) Get

func (m *MockIMultiValue) Get(arg0, arg1 string) (string, error)

Get mocks base method

func (*MockIMultiValue) Has

func (m *MockIMultiValue) Has(arg0, arg1 string) (bool, error)

Has mocks base method

func (*MockIMultiValue) Keys

func (m *MockIMultiValue) Keys(arg0, arg1 string) ([]string, error)

Keys mocks base method

func (*MockIMultiValue) Put

func (m *MockIMultiValue) Put(arg0, arg1, arg2 string) error

Put mocks base method

func (*MockIMultiValue) Rollback

func (m *MockIMultiValue) Rollback()

Rollback mocks base method

type MockIMultiValueMockRecorder

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

MockIMultiValueMockRecorder is the mock recorder for MockIMultiValue

func (*MockIMultiValueMockRecorder) Commit

func (mr *MockIMultiValueMockRecorder) Commit() *gomock.Call

Commit indicates an expected call of Commit

func (*MockIMultiValueMockRecorder) Del

func (mr *MockIMultiValueMockRecorder) Del(arg0, arg1 interface{}) *gomock.Call

Del indicates an expected call of Del

func (*MockIMultiValueMockRecorder) Get

func (mr *MockIMultiValueMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockIMultiValueMockRecorder) Has

func (mr *MockIMultiValueMockRecorder) Has(arg0, arg1 interface{}) *gomock.Call

Has indicates an expected call of Has

func (*MockIMultiValueMockRecorder) Keys

func (mr *MockIMultiValueMockRecorder) Keys(arg0, arg1 interface{}) *gomock.Call

Keys indicates an expected call of Keys

func (*MockIMultiValueMockRecorder) Put

func (mr *MockIMultiValueMockRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call

Put indicates an expected call of Put

func (*MockIMultiValueMockRecorder) Rollback

func (mr *MockIMultiValueMockRecorder) Rollback() *gomock.Call

Rollback indicates an expected call of Rollback

type RollbackHandler

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

RollbackHandler rollback delegate

func (*RollbackHandler) Commit

func (m *RollbackHandler) Commit()

Commit commit a MVCC version

func (*RollbackHandler) Rollback

func (m *RollbackHandler) Rollback()

Rollback rollback to newest MVCC version

type SerializedJSON

type SerializedJSON []byte

SerializedJSON type of Serialized json

type SimpleDB

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

SimpleDB implements simple database interface

func NewDatabase

func NewDatabase() *SimpleDB

NewDatabase returns a SimpleDB with empty data and system contract

func NewDatabaseFromPath

func NewDatabaseFromPath(path string) *SimpleDB

NewDatabaseFromPath returns a SimpleDB with data loaded from json file

func (*SimpleDB) AddSystem

func (d *SimpleDB) AddSystem(path string)

AddSystem load system contract and data from json file

func (*SimpleDB) Commit

func (d *SimpleDB) Commit()

Commit do nothing

func (*SimpleDB) Del

func (d *SimpleDB) Del(table string, key string) error

Del delete key from db

func (*SimpleDB) Get

func (d *SimpleDB) Get(table string, key string) (string, error)

Get key-value from db with marshal

func (*SimpleDB) Has

func (d *SimpleDB) Has(table string, key string) (bool, error)

Has return if key exists in db

func (*SimpleDB) Keys

func (d *SimpleDB) Keys(table string, prefix string) ([]string, error)

Keys do nothing

func (*SimpleDB) Load

func (d *SimpleDB) Load(path string) error

Load load db data from json file

func (*SimpleDB) Put

func (d *SimpleDB) Put(table string, key string, value string) error

Put key-value into db with unmarshal

func (*SimpleDB) Rollback

func (d *SimpleDB) Rollback()

Rollback do nothing

func (*SimpleDB) Save

func (d *SimpleDB) Save(path string) error

Save save db data to json file

type Visitor

Visitor combine of every handler, to be api of database

func NewVisitor

func NewVisitor(cacheLength int, cb IMultiValue) *Visitor

NewVisitor get a visitor of a DB, with cache length determined

Jump to

Keyboard shortcuts

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