statesqldb

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DbType_Mysql = "mysql"
View Source
var DbType_Sqlite = "sqlite"

Functions

This section is empty.

Types

type MemberExtraInfo

type MemberExtraInfo struct {
	MemberHash []byte `gorm:"size:32;primaryKey"`
	MemberType int    `gorm:""`
	MemberInfo []byte `gorm:"size:2000"`
	OrgId      string `gorm:"size:200"`
	Seq        uint64 //防止Sequence是数据库关键字
}

MemberExtraInfo defines mysql orm model, used to create mysql table 'member_extra_infos'

func NewMemberExtraInfo

func NewMemberExtraInfo(member *accesscontrol.Member, extra *accesscontrol.MemberExtraData) *MemberExtraInfo

func (*MemberExtraInfo) GetCountSql

func (b *MemberExtraInfo) GetCountSql() (string, []interface{})

func (*MemberExtraInfo) GetCreateTableSql

func (b *MemberExtraInfo) GetCreateTableSql(dbType string) string

func (*MemberExtraInfo) GetExtraData

func (b *MemberExtraInfo) GetExtraData() *accesscontrol.MemberExtraData

func (*MemberExtraInfo) GetInsertSql

func (b *MemberExtraInfo) GetInsertSql(dbType string) (string, []interface{})

func (*MemberExtraInfo) GetSaveSql

func (b *MemberExtraInfo) GetSaveSql() (string, []interface{})

func (*MemberExtraInfo) GetTableName

func (b *MemberExtraInfo) GetTableName() string

func (*MemberExtraInfo) GetUpdateSql

func (b *MemberExtraInfo) GetUpdateSql() (string, []interface{})

func (*MemberExtraInfo) ScanObject

func (b *MemberExtraInfo) ScanObject(scan func(dest ...interface{}) error) error

type NewDbHandleFunc

type NewDbHandleFunc func(dbName string) (protocol.SqlDBHandle, error)

NewStateSqlDB construct a new `StateDB` for given chainId

func NewStateSqlDB(chainId string, dbConfig *localconf.SqlDbConfig, logger protocol.Logger) (*StateSqlDB, error) {
	dbName := getDbName("dbConfig", chainId)
	db := rawsqlprovider.NewSqlDBHandle(dbName, dbConfig, logger)
	return newStateSqlDB(dbName, chainId, db, dbConfig, logger)
}

type StateInfo

type StateInfo struct {
	//ID           uint   `gorm:"primarykey"`
	ContractName string `gorm:"size:128;primaryKey"`
	ObjectKey    []byte `gorm:"size:128;primaryKey;default:''"`
	ObjectValue  []byte `gorm:"type:longblob"`
	BlockHeight  uint64 `gorm:"index:idx_height"`
	//CreatedAt    time.Time `gorm:"default:null"`
	UpdatedAt time.Time `gorm:"default:null"`
}

StateInfo defines mysql orm model, used to create mysql table 'state_infos'

func NewStateInfo

func NewStateInfo(contractName string, objectKey []byte, objectValue []byte, blockHeight uint64,
	t time.Time) *StateInfo

NewStateInfo construct a new StateInfo

func (*StateInfo) GetCountSql

func (b *StateInfo) GetCountSql() (string, []interface{})

func (*StateInfo) GetCreateTableSql

func (b *StateInfo) GetCreateTableSql(dbType string) string

func (*StateInfo) GetInsertSql

func (b *StateInfo) GetInsertSql(dbType string) (string, []interface{})

func (*StateInfo) GetTableName

func (b *StateInfo) GetTableName() string

func (*StateInfo) GetUpdateSql

func (b *StateInfo) GetUpdateSql() (string, []interface{})

func (*StateInfo) ScanObject

func (b *StateInfo) ScanObject(scan func(dest ...interface{}) error) error

type StateRecordSql

type StateRecordSql struct {
	// id is sql hash
	Id           string    `gorm:"size:64;primaryKey"`
	ContractName string    `gorm:"size:100"`
	SqlString    string    `gorm:"size:4000"`
	SqlType      int       `gorm:"size:1;default:1"`
	Version      string    `gorm:"size:20"`
	Status       int       `gorm:"default:0"` //0: start process, 1:success 2:fail
	UpdatedAt    time.Time `gorm:"default:null"`
}

StateRecordSql defines mysql orm model, used to create mysql table 'state_record_sql'

func NewStateRecordSql

func NewStateRecordSql(contractName string, sql string, sqlType protocol.SqlType,
	version string, status int) *StateRecordSql

NewStateRecordSql construct a new StateRecordSql

func (*StateRecordSql) GetCountSql

func (b *StateRecordSql) GetCountSql() (string, []interface{})

func (*StateRecordSql) GetCreateTableSql

func (b *StateRecordSql) GetCreateTableSql(dbType string) string

func (*StateRecordSql) GetInsertSql

func (b *StateRecordSql) GetInsertSql(dbType string) (string, []interface{})

func (*StateRecordSql) GetQueryStatusSql

func (b *StateRecordSql) GetQueryStatusSql() (string, interface{})

func (*StateRecordSql) GetTableName

func (b *StateRecordSql) GetTableName() string

func (*StateRecordSql) GetUpdateSql

func (b *StateRecordSql) GetUpdateSql() (string, []interface{})

type StateSqlDB

type StateSqlDB struct {
	sync.Mutex
	// contains filtered or unexported fields
}

StateSqlDB provider a implementation of `statedb.StateDB` This implementation provides a mysql based data model

func NewStateSqlDB

func NewStateSqlDB(dbPrefix, chainId string, db protocol.SqlDBHandle, newDbHandle NewDbHandleFunc,
	logger protocol.Logger, sqlDbConnPoolSize int) (*StateSqlDB, error)

func (*StateSqlDB) BeginDbTransaction

func (s *StateSqlDB) BeginDbTransaction(txName string) (protocol.SqlDBTransaction, error)

func (*StateSqlDB) Close

func (s *StateSqlDB) Close()

Close is used to close database, there is no need for gorm to close db

func (*StateSqlDB) CommitBlock

func (s *StateSqlDB) CommitBlock(blockWithRWSet *serialization.BlockWithSerializedInfo, isCache bool) error

CommitBlock commits the state in an atomic operation

func (*StateSqlDB) CommitDbTransaction

func (s *StateSqlDB) CommitDbTransaction(txName string) error

func (*StateSqlDB) CreateDatabase

func (s *StateSqlDB) CreateDatabase(contractName string) error

func (*StateSqlDB) DropDatabase

func (s *StateSqlDB) DropDatabase(contractName string) error

DropDatabase 删除一个合约对应的数据库

func (*StateSqlDB) ExecDdlSql

func (s *StateSqlDB) ExecDdlSql(contractName, sql, version string) error

func (*StateSqlDB) GetChainConfig

func (s *StateSqlDB) GetChainConfig() (*configPb.ChainConfig, error)

func (*StateSqlDB) GetContractByName added in v2.1.1

func (s *StateSqlDB) GetContractByName(name string) (*commonPb.Contract, error)

func (*StateSqlDB) GetContractBytecode added in v2.1.1

func (s *StateSqlDB) GetContractBytecode(name string) ([]byte, error)

func (*StateSqlDB) GetContractDbName

func (s *StateSqlDB) GetContractDbName(contractName string) string

GetContractDbName 获得一个合约对应的状态数据库名

func (*StateSqlDB) GetDbTransaction

func (s *StateSqlDB) GetDbTransaction(txName string) (protocol.SqlDBTransaction, error)

func (*StateSqlDB) GetLastSavepoint

func (s *StateSqlDB) GetLastSavepoint() (uint64, error)

GetLastSavepoint returns the last block height

func (*StateSqlDB) GetMemberExtraData

func (s *StateSqlDB) GetMemberExtraData(member *accesscontrol.Member) (*accesscontrol.MemberExtraData, error)

func (*StateSqlDB) InitGenesis

func (s *StateSqlDB) InitGenesis(genesisBlock *serialization.BlockWithSerializedInfo) error

func (*StateSqlDB) QueryMulti

func (s *StateSqlDB) QueryMulti(contractName, sql string, values ...interface{}) (protocol.SqlRows, error)

func (*StateSqlDB) QuerySingle

func (s *StateSqlDB) QuerySingle(contractName, sql string, values ...interface{}) (protocol.SqlRow, error)

func (*StateSqlDB) ReadObject

func (s *StateSqlDB) ReadObject(contractName string, key []byte) ([]byte, error)

ReadObject returns the state value for given contract name and key, or returns nil if none exists.

func (*StateSqlDB) RollbackDbTransaction

func (s *StateSqlDB) RollbackDbTransaction(txName string) error

func (*StateSqlDB) SelectObject

func (s *StateSqlDB) SelectObject(contractName string, startKey []byte, limit []byte) (protocol.StateIterator, error)

SelectObject returns an iterator that contains all the key-values between given key ranges. startKey is included in the results and limit is excluded.

Jump to

Keyboard shortcuts

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