store_sqldb

package module
v0.0.0-...-cc595fb Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

README

store-sqldb

介绍

perseus 链存储组件-sqldb

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

View Source
const DELETE_SQL = "DELETE FROM key_values WHERE object_key=?"
View Source
const DSN_ParseTime = "parseTime=True"
View Source
const DbType_MySQL = "mysql"
View Source
const DbType_Sqlite = "sqlite"
View Source
const DbType_TDSQL = "tdsql"
View Source
const PUT_KV_SQL = "REPLACE INTO key_values(`object_key`,`object_value`) VALUES(?, ?)"
View Source
const UTF8_CHAR = "charset=utf8mb4"

Variables

This section is empty.

Functions

func ParseSqlDbType

func ParseSqlDbType(str string) (string, error)

Types

type KeyValue

type KeyValue struct {
	ObjectKey   []byte `gorm:"size:128;primaryKey;default:''"`
	ObjectValue []byte `gorm:"type:longblob"`
}

func (*KeyValue) GetCountSql

func (kv *KeyValue) GetCountSql() (string, []interface{})

func (*KeyValue) GetCreateTableSql

func (kv *KeyValue) GetCreateTableSql(dbType string) string

func (*KeyValue) GetInsertSql

func (kv *KeyValue) GetInsertSql(dbType string) (string, []interface{})

func (*KeyValue) GetSaveSql

func (kv *KeyValue) GetSaveSql(dbType string) (string, []interface{})

func (*KeyValue) GetTableName

func (kv *KeyValue) GetTableName() string

func (*KeyValue) GetUpdateSql

func (kv *KeyValue) GetUpdateSql() (string, []interface{})

type NewSqlDBOptions

type NewSqlDBOptions struct {
	Config    *SqlDbConfig
	Logger    protocol.Logger
	Encryptor crypto.SymmetricKey
	ChainId   string
	DbName    string
}

type SqlDBHandle

type SqlDBHandle struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewKVDBHandle

func NewKVDBHandle(input *NewSqlDBOptions) *SqlDBHandle

NewKVDBHandle construct a new SqlDBHandle

func NewMemSqlDBHandle

func NewMemSqlDBHandle(log protocol.Logger) *SqlDBHandle

NewMemSqlDBHandle for unit test

func NewShareMemSqlDBHandle

func NewShareMemSqlDBHandle(log protocol.Logger) *SqlDBHandle

NewShareMemSqlDBHandle share cache

func NewSqlDBHandle

func NewSqlDBHandle(input *NewSqlDBOptions) *SqlDBHandle

NewSqlDBHandle construct a new SqlDBHandle

func (*SqlDBHandle) BeginDbTransaction

func (p *SqlDBHandle) BeginDbTransaction(txName string) (protocol.SqlDBTransaction, error)

func (*SqlDBHandle) Close

func (p *SqlDBHandle) Close() error

func (*SqlDBHandle) CommitDbTransaction

func (p *SqlDBHandle) CommitDbTransaction(txName string) error

func (*SqlDBHandle) CompactRange

func (p *SqlDBHandle) CompactRange(start, limit []byte) error

func (*SqlDBHandle) CreateDatabaseIfNotExist

func (p *SqlDBHandle) CreateDatabaseIfNotExist(dbName string) (bool, error)

CreateDatabaseIfNotExist 如果数据库不存在则创建对应的数据库,创建后将当前数据库设置为新数据库,返回是否已存在

func (*SqlDBHandle) CreateTable

func (p *SqlDBHandle) CreateTable(obj TableDDLGenerator) error

func (*SqlDBHandle) CreateTableIfNotExist

func (p *SqlDBHandle) CreateTableIfNotExist(objI interface{}) error

CreateTableIfNotExist 根据一个对象struct,自动构建对应的sql数据库表

func (*SqlDBHandle) Delete

func (p *SqlDBHandle) Delete(key []byte) error

Delete deletes the given key

func (*SqlDBHandle) ExecSql

func (p *SqlDBHandle) ExecSql(sql string, values ...interface{}) (int64, error)

ExecSql 执行SQL语句

func (*SqlDBHandle) Get

func (p *SqlDBHandle) Get(key []byte) ([]byte, error)

Get returns the value for the given key, or returns nil if none exists

func (*SqlDBHandle) GetDbTransaction

func (p *SqlDBHandle) GetDbTransaction(txName string) (protocol.SqlDBTransaction, error)

func (*SqlDBHandle) GetDbType

func (p *SqlDBHandle) GetDbType() string

GetDbType returns db type

func (*SqlDBHandle) GetSqlDbType

func (p *SqlDBHandle) GetSqlDbType() string

func (*SqlDBHandle) GetWriteBatchSize

func (p *SqlDBHandle) GetWriteBatchSize() uint64

GetWriteBatchSize return write batch size

func (*SqlDBHandle) Has

func (p *SqlDBHandle) Has(key []byte) (bool, error)

Has return true if the given key exist, or return false if none exists

func (*SqlDBHandle) HasTable

func (p *SqlDBHandle) HasTable(tableName string) (bool, error)

func (*SqlDBHandle) NewIteratorWithPrefix

func (p *SqlDBHandle) NewIteratorWithPrefix(prefix []byte) (protocol.Iterator, error)

NewIteratorWithPrefix returns an iterator that contains all the key-values with given prefix

func (*SqlDBHandle) NewIteratorWithRange

func (p *SqlDBHandle) NewIteratorWithRange(start []byte, limit []byte) (protocol.Iterator, error)

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

func (*SqlDBHandle) Put

func (p *SqlDBHandle) Put(key []byte, value []byte) error

Put saves the key-values

func (*SqlDBHandle) QueryMulti

func (p *SqlDBHandle) QueryMulti(sql string, values ...interface{}) (protocol.SqlRows, error)

func (*SqlDBHandle) QuerySingle

func (p *SqlDBHandle) QuerySingle(sql string, values ...interface{}) (protocol.SqlRow, error)

func (*SqlDBHandle) RollbackDbTransaction

func (p *SqlDBHandle) RollbackDbTransaction(txName string) error

func (*SqlDBHandle) Save

func (p *SqlDBHandle) Save(val interface{}) (int64, error)

func (*SqlDBHandle) WriteBatch

func (p *SqlDBHandle) WriteBatch(batch protocol.StoreBatcher, sync bool) error

WriteBatch writes a batch in an atomic operation

type SqlDBRow

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

func NewSqlDBRow

func NewSqlDBRow(row *sql.Rows) *SqlDBRow

func (*SqlDBRow) Data

func (row *SqlDBRow) Data() (map[string][]byte, error)

func (*SqlDBRow) IsEmpty

func (row *SqlDBRow) IsEmpty() bool

func (*SqlDBRow) ScanColumns

func (r *SqlDBRow) ScanColumns(dest ...interface{}) error

type SqlDBRows

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

func NewSqlDBRows

func NewSqlDBRows(rows *sql.Rows, close func() error) *SqlDBRows

func (*SqlDBRows) Close

func (r *SqlDBRows) Close() error

func (*SqlDBRows) Data

func (r *SqlDBRows) Data() (map[string][]byte, error)

func (*SqlDBRows) Next

func (r *SqlDBRows) Next() bool

func (*SqlDBRows) ScanColumns

func (r *SqlDBRows) ScanColumns(dest ...interface{}) error

type SqlDBTx

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

func NewSqlDBTx

func NewSqlDBTx(name string, dbType string, db *sql.Tx, logger protocol.Logger) *SqlDBTx

func (*SqlDBTx) BeginDbSavePoint

func (p *SqlDBTx) BeginDbSavePoint(spName string) error

func (*SqlDBTx) ChangeContextDb

func (p *SqlDBTx) ChangeContextDb(dbName string) error

func (*SqlDBTx) Commit

func (p *SqlDBTx) Commit() error

func (*SqlDBTx) ExecSql

func (p *SqlDBTx) ExecSql(sql string, values ...interface{}) (int64, error)

func (*SqlDBTx) QueryMulti

func (p *SqlDBTx) QueryMulti(sql string, values ...interface{}) (protocol.SqlRows, error)

func (*SqlDBTx) QuerySingle

func (p *SqlDBTx) QuerySingle(sql string, values ...interface{}) (protocol.SqlRow, error)

func (*SqlDBTx) Rollback

func (p *SqlDBTx) Rollback() error

func (*SqlDBTx) RollbackDbSavePoint

func (p *SqlDBTx) RollbackDbSavePoint(spName string) error

func (*SqlDBTx) Save

func (p *SqlDBTx) Save(val interface{}) (int64, error)

func (*SqlDBTx) SaveBatch

func (p *SqlDBTx) SaveBatch(vals []interface{}) (int64, error)

SaveBatch 批量的保存同一种对象的多个实例

type SqlDbConfig

type SqlDbConfig struct {
	//mysql, sqlite, postgres, sqlserver
	SqlDbType       string `mapstructure:"sqldb_type"`
	Dsn             string `mapstructure:"dsn"`
	MaxIdleConns    int    `mapstructure:"max_idle_conns"`
	MaxOpenConns    int    `mapstructure:"max_open_conns"`
	ConnMaxLifeTime int    `mapstructure:"conn_max_lifetime"` //second
	SqlLogMode      string `mapstructure:"sqllog_mode"`       //Silent,Error,Warn,Info
	SqlVerifier     string `mapstructure:"sql_verifier"`      //simple,safe
	DbPrefix        string `mapstructure:"db_prefix"`
}

type TableDDLGenerator

type TableDDLGenerator interface {
	GetCreateTableSql(dbType string) string
	GetTableName() string
}

type TableDMLGenerator

type TableDMLGenerator interface {
	GetInsertSql(dbType string) (string, []interface{})
	GetUpdateSql() (string, []interface{})
	GetCountSql() (string, []interface{})
}

type UserDefineSave

type UserDefineSave interface {
	GetSaveSql(dbType string) (string, []interface{})
}

Jump to

Keyboard shortcuts

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