sqldb

package
v1.13.8 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 22 Imported by: 0

Documentation

Overview

Package sqldb is a generated GoMock package.

Index

Constants

View Source
const (
	// SystemNamespace system namespace
	SystemNamespace = "Polaris"
	// STORENAME database storage name
	STORENAME = "defaultStore"
	// DefaultConnMaxLifetime default maximum connection lifetime
	DefaultConnMaxLifetime = 60 * 30 // 默认是30分钟
)
View Source
const (
	// IDAttribute is the name of the attribute that stores the ID of the object.
	IDAttribute string = "id"

	// NameAttribute will be used as the name of the attribute that stores the name of the object.
	NameAttribute string = "name"

	// FlagAttribute will be used as the name of the attribute that stores the flag of the object.
	FlagAttribute string = "flag"

	// GroupIDAttribute will be used as the name of the attribute that stores the group ID of the object.
	GroupIDAttribute string = "group_id"
)
View Source
const (
	DefaultElectKey = "polaris-server"
	TickTime        = 2
	LeaseTime       = 10
)
View Source
const (

	// OwnerAttribute
	OwnerAttribute string = "owner"

	// And
	And string = " and"
)

Variables

View Source
var (
	RuleFilters map[string]string = map[string]string{
		"res_id":         "ar.res_id",
		"res_type":       "ar.res_type",
		"default":        "ag.default",
		"owner":          "ag.owner",
		"name":           "ag.name",
		"principal_id":   "ap.principal_id",
		"principal_type": "ap.principal_role",
	}

	RuleNeedLikeFilters map[string]struct{} = map[string]struct{}{
		"name": {},
	}
)
View Source
var (
	ErrMultipleConfigFileGroupFound error = errors.New("multiple config_file_group found")
)

Functions

func BatchOperation

func BatchOperation(label string, data []interface{}, handler BatchHandler) error

BatchOperation 批量操作 @note 每次最多操作100个

func BatchQuery

func BatchQuery(label string, data []interface{}, handler BatchHandler) error

BatchQuery 批量查询数据的对外接口 每次最多查询200个

func NewSqlDBTx

func NewSqlDBTx(delegateTx *BaseTx) store.Tx

func PlaceholdersN

func PlaceholdersN(size int) string

PlaceholdersN 构造多个占位符

func Retry

func Retry(label string, handle func() error)

Retry 重试主函数 最多重试20次,每次等待5ms*重试次数

func RetryTransaction

func RetryTransaction(label string, handle func() error) error

RetryTransaction 事务重试

Types

type BaseDB

type BaseDB struct {
	*sql.DB
	// contains filtered or unexported fields
}

BaseDB 对sql.DB的封装

func NewBaseDB

func NewBaseDB(cfg *dbConfig, parsePwd plugin.ParsePassword) (*BaseDB, error)

NewBaseDB 新建一个BaseDB

func (*BaseDB) Begin

func (b *BaseDB) Begin() (*BaseTx, error)

Begin 重写db.Begin

func (*BaseDB) Exec

func (b *BaseDB) Exec(query string, args ...interface{}) (sql.Result, error)

Exec 重写db.Exec函数 提供重试功能

func (*BaseDB) Query

func (b *BaseDB) Query(query string, args ...interface{}) (*sql.Rows, error)

Query 重写db.Query函数

type BaseTx

type BaseTx struct {
	*sql.Tx
}

BaseTx 对sql.Tx的封装

type BatchHandler

type BatchHandler func(objects []interface{}) error

BatchHandler 批量查询数据的回调函数

type LeaderElectionStore added in v1.13.1

type LeaderElectionStore interface {
	// GetVersion get current version
	GetVersion(key string) (int64, error)
	// CompareAndSwapVersion cas version
	CompareAndSwapVersion(key string, curVersion int64, newVersion int64, leader string) (bool, error)
	// CheckMtimeExpired check mtime expired
	CheckMtimeExpired(key string, leaseTime int32) (bool, error)
}

LeaderElectionStore store inteface

type MockLeaderElectionStore added in v1.13.1

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

MockLeaderElectionStore is a mock of LeaderElectionStore interface.

func NewMockLeaderElectionStore added in v1.13.1

func NewMockLeaderElectionStore(ctrl *gomock.Controller) *MockLeaderElectionStore

NewMockLeaderElectionStore creates a new mock instance.

func (*MockLeaderElectionStore) CheckMtimeExpired added in v1.13.1

func (m *MockLeaderElectionStore) CheckMtimeExpired(key string, leaseTime int32) (bool, error)

CheckMtimeExpired mocks base method.

func (*MockLeaderElectionStore) CompareAndSwapVersion added in v1.13.1

func (m *MockLeaderElectionStore) CompareAndSwapVersion(key string, curVersion, newVersion int64, leader string) (bool, error)

CompareAndSwapVersion mocks base method.

func (*MockLeaderElectionStore) EXPECT added in v1.13.1

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

func (*MockLeaderElectionStore) GetVersion added in v1.13.1

func (m *MockLeaderElectionStore) GetVersion(key string) (int64, error)

GetVersion mocks base method.

type MockLeaderElectionStoreMockRecorder added in v1.13.1

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

MockLeaderElectionStoreMockRecorder is the mock recorder for MockLeaderElectionStore.

func (*MockLeaderElectionStoreMockRecorder) CheckMtimeExpired added in v1.13.1

func (mr *MockLeaderElectionStoreMockRecorder) CheckMtimeExpired(key, leaseTime interface{}) *gomock.Call

CheckMtimeExpired indicates an expected call of CheckMtimeExpired.

func (*MockLeaderElectionStoreMockRecorder) CompareAndSwapVersion added in v1.13.1

func (mr *MockLeaderElectionStoreMockRecorder) CompareAndSwapVersion(key, curVersion, newVersion, leader interface{}) *gomock.Call

CompareAndSwapVersion indicates an expected call of CompareAndSwapVersion.

func (*MockLeaderElectionStoreMockRecorder) GetVersion added in v1.13.1

func (mr *MockLeaderElectionStoreMockRecorder) GetVersion(key interface{}) *gomock.Call

GetVersion indicates an expected call of GetVersion.

type Order

type Order struct {
	Filed    string
	Sequence string
}

Order 排序结构体

type Page

type Page struct {
	Offset uint32
	Limit  uint32
}

Page 分页结构体

type QueryHandler

type QueryHandler func(query string, args ...interface{}) (*sql.Rows, error)

QueryHandler is the interface that wraps the basic Query method.

type Tx

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

func (*Tx) Commit

func (t *Tx) Commit() error

func (*Tx) GetDelegateTx

func (t *Tx) GetDelegateTx() interface{}

func (*Tx) Rollback

func (t *Tx) Rollback() error

Jump to

Keyboard shortcuts

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