sqldb

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TickTime  = 2
	LeaseTime = 10
)
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 (

	// 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 (
	ErrTxIsNil = errors.New("tx is nil")
)

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

type LeaderElectionStore interface {
	// CreateLeaderElection
	CreateLeaderElection(key string) error
	// 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) (string, bool, error)
	// ListLeaderElections list all leaderelection
	ListLeaderElections() ([]*model.LeaderElection, error)
}

LeaderElectionStore store inteface

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) CreateReadView added in v1.17.3

func (t *Tx) CreateReadView() 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