Documentation ¶
Index ¶
- Constants
- func ParseSqlDbType(str string) (string, error)
- type KeyValue
- func (kv *KeyValue) GetCountSql() (string, []interface{})
- func (kv *KeyValue) GetCreateTableSql(dbType string) string
- func (kv *KeyValue) GetInsertSql(dbType string) (string, []interface{})
- func (kv *KeyValue) GetSaveSql(dbType string) (string, []interface{})
- func (kv *KeyValue) GetTableName() string
- func (kv *KeyValue) GetUpdateSql() (string, []interface{})
- type NewSqlDBOptions
- type SqlDBHandle
- func (p *SqlDBHandle) BeginDbTransaction(txName string) (protocol.SqlDBTransaction, error)
- func (p *SqlDBHandle) Close() error
- func (p *SqlDBHandle) CommitDbTransaction(txName string) error
- func (p *SqlDBHandle) CompactRange(start, limit []byte) error
- func (p *SqlDBHandle) CreateDatabaseIfNotExist(dbName string) (bool, error)
- func (p *SqlDBHandle) CreateTable(obj TableDDLGenerator) error
- func (p *SqlDBHandle) CreateTableIfNotExist(objI interface{}) error
- func (p *SqlDBHandle) Delete(key []byte) error
- func (p *SqlDBHandle) ExecSql(sql string, values ...interface{}) (int64, error)
- func (p *SqlDBHandle) Get(key []byte) ([]byte, error)
- func (p *SqlDBHandle) GetDbTransaction(txName string) (protocol.SqlDBTransaction, error)
- func (p *SqlDBHandle) GetDbType() string
- func (p *SqlDBHandle) GetSqlDbType() string
- func (p *SqlDBHandle) GetWriteBatchSize() uint64
- func (p *SqlDBHandle) Has(key []byte) (bool, error)
- func (p *SqlDBHandle) HasTable(tableName string) (bool, error)
- func (p *SqlDBHandle) NewIteratorWithPrefix(prefix []byte) (protocol.Iterator, error)
- func (p *SqlDBHandle) NewIteratorWithRange(start []byte, limit []byte) (protocol.Iterator, error)
- func (p *SqlDBHandle) Put(key []byte, value []byte) error
- func (p *SqlDBHandle) QueryMulti(sql string, values ...interface{}) (protocol.SqlRows, error)
- func (p *SqlDBHandle) QuerySingle(sql string, values ...interface{}) (protocol.SqlRow, error)
- func (p *SqlDBHandle) RollbackDbTransaction(txName string) error
- func (p *SqlDBHandle) Save(val interface{}) (int64, error)
- func (p *SqlDBHandle) WriteBatch(batch protocol.StoreBatcher, sync bool) error
- type SqlDBRow
- type SqlDBRows
- type SqlDBTx
- func (p *SqlDBTx) BeginDbSavePoint(spName string) error
- func (p *SqlDBTx) ChangeContextDb(dbName string) error
- func (p *SqlDBTx) Commit() error
- func (p *SqlDBTx) ExecSql(sql string, values ...interface{}) (int64, error)
- func (p *SqlDBTx) QueryMulti(sql string, values ...interface{}) (protocol.SqlRows, error)
- func (p *SqlDBTx) QuerySingle(sql string, values ...interface{}) (protocol.SqlRow, error)
- func (p *SqlDBTx) Rollback() error
- func (p *SqlDBTx) RollbackDbSavePoint(spName string) error
- func (p *SqlDBTx) Save(val interface{}) (int64, error)
- func (p *SqlDBTx) SaveBatch(vals []interface{}) (int64, error)
- type SqlDbConfig
- type TableDDLGenerator
- type TableDMLGenerator
- type UserDefineSave
Constants ¶
const DELETE_SQL = "DELETE FROM key_values WHERE object_key=?"
const DSN_ParseTime = "parseTime=True"
const DbType_MySQL = "mysql"
const DbType_Sqlite = "sqlite"
const DbType_TDSQL = "tdsql"
const PUT_KV_SQL = "REPLACE INTO key_values(`object_key`,`object_value`) VALUES(?, ?)"
const UTF8_CHAR = "charset=utf8mb4"
Variables ¶
This section is empty.
Functions ¶
func ParseSqlDbType ¶
Types ¶
type KeyValue ¶
type KeyValue struct { ObjectKey []byte `gorm:"size:128;primaryKey;default:''"` ObjectValue []byte `gorm:"type:longblob"` }
func (*KeyValue) GetCountSql ¶
func (*KeyValue) GetCreateTableSql ¶
func (*KeyValue) GetInsertSql ¶
func (*KeyValue) GetSaveSql ¶
func (*KeyValue) GetTableName ¶
func (*KeyValue) GetUpdateSql ¶
type NewSqlDBOptions ¶
type NewSqlDBOptions struct { Config *SqlDbConfig Logger protocol.Logger Encryptor crypto.SymmetricKey ChainId string DbName string }
type SqlDBHandle ¶
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) 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) 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 ¶
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 (*SqlDBRow) ScanColumns ¶
type SqlDBRows ¶
type SqlDBRows struct {
// contains filtered or unexported fields
}
func (*SqlDBRows) ScanColumns ¶
type SqlDBTx ¶
func NewSqlDBTx ¶
func (*SqlDBTx) BeginDbSavePoint ¶
func (*SqlDBTx) ChangeContextDb ¶
func (*SqlDBTx) QueryMulti ¶
func (*SqlDBTx) QuerySingle ¶
func (*SqlDBTx) RollbackDbSavePoint ¶
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"` }