proto

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommandType

func CommandType(ctx context.Context) byte

CommandType extracts command type

func ConnectionID

func ConnectionID(ctx context.Context) uint32

ConnectionID extracts connection id

func IsMaster

func IsMaster(ctx context.Context) bool

IsMaster returns true if force using master.

func IsSlave

func IsSlave(ctx context.Context) bool

IsSlave returns true if force using master.

func QueryStmt

func QueryStmt(ctx context.Context) ast.StmtNode

QueryStmt extracts query stmt

func RemoteAddr added in v0.2.0

func RemoteAddr(ctx context.Context) string

RemoteAddr extracts remote addr

func Schema

func Schema(ctx context.Context) string

Schema extracts schema

func SqlText added in v0.2.0

func SqlText(ctx context.Context) string

SqlText extracts sql text

func UserName added in v0.2.0

func UserName(ctx context.Context) string

UserName extracts user name

func Variable

func Variable(ctx context.Context, key string) interface{}

Variable extracts variable value

func WithCommandType

func WithCommandType(ctx context.Context, commandType byte) context.Context

WithCommandType binds command type

func WithConnectionID

func WithConnectionID(ctx context.Context, connectionID uint32) context.Context

WithConnectionID binds connection id

func WithDBGroupTx added in v0.5.0

func WithDBGroupTx(ctx context.Context, tx DBGroupTx) context.Context

WithDBGroupTx .

func WithMaster

func WithMaster(ctx context.Context) context.Context

WithMaster uses master datasource.

func WithPrepareStmt

func WithPrepareStmt(ctx context.Context, stmt *Stmt) context.Context

WithPrepareStmt binds prepare stmt

func WithQueryStmt

func WithQueryStmt(ctx context.Context, stmt ast.StmtNode) context.Context

WithQueryStmt binds query stmt

func WithRemoteAddr added in v0.2.0

func WithRemoteAddr(ctx context.Context, remoteAddr string) context.Context

WithRemoteAddr binds remote address

func WithSchema

func WithSchema(ctx context.Context, schema string) context.Context

WithSchema binds schema

func WithSlave

func WithSlave(ctx context.Context) context.Context

WithSlave uses slave datasource.

func WithSqlText added in v0.2.0

func WithSqlText(ctx context.Context, sqlText string) context.Context

WithSqlText binds sql text

func WithUserName added in v0.2.0

func WithUserName(ctx context.Context, userName string) context.Context

WithUserName binds user name

func WithVariable

func WithVariable(ctx context.Context, key string, value interface{}) bool

WithVariable binds a key value pair

func WithVariableMap

func WithVariableMap(ctx context.Context) context.Context

WithVariableMap binds a map[string]interface{} to store temp variable

Types

type Connection

type Connection interface {
	DataSourceName() string
	Connect(ctx context.Context) error
	Close()
}

type DB

type DB interface {
	Name() string
	Status() DBStatus
	SetCapacity(capacity int) error
	SetIdleTimeout(idleTimeout time.Duration)
	Capacity() int64
	Available() int64
	Active() int64
	InUse() int64
	MaxCap() int64
	WaitCount() int64
	WaitTime() time.Duration
	IdleTimeout() time.Duration
	IdleClosed() int64
	Exhausted() int64
	StatsJSON() string
	Ping() error
	Close()
	IsClosed() bool

	IsMaster() bool
	MasterName() string
	SetWriteWeight(int)
	SetReadWeight(int)
	WriteWeight() int
	ReadWeight() int

	SetConnectionPreFilters(filters []DBConnectionPreFilter)
	SetConnectionPostFilters(filters []DBConnectionPostFilter)

	UseDB(ctx context.Context, schema string) error
	ExecuteFieldList(ctx context.Context, table, wildcard string) ([]Field, error)
	Query(ctx context.Context, query string) (Result, uint16, error)
	QueryDirectly(query string) (Result, uint16, error)
	ExecuteStmt(ctx context.Context, stmt *Stmt) (Result, uint16, error)
	ExecuteSql(ctx context.Context, sql string, args ...interface{}) (Result, uint16, error)
	ExecuteSqlDirectly(sql string, args ...interface{}) (Result, uint16, error)
	Begin(ctx context.Context) (Tx, Result, error)
	XAStart(ctx context.Context, sql string) (Tx, Result, error)
}

type DBConnectionPostFilter

type DBConnectionPostFilter interface {
	Filter
	PostHandle(ctx context.Context, result Result, conn Connection) error
}

type DBConnectionPreFilter

type DBConnectionPreFilter interface {
	Filter
	PreHandle(ctx context.Context, conn Connection) error
}

type DBGroupExecutor

type DBGroupExecutor interface {
	GroupName() string
	Begin(ctx context.Context) (Tx, Result, error)
	Query(ctx context.Context, query string) (Result, uint16, error)
	QueryAll(ctx context.Context, query string) (Result, uint16, error)
	Execute(ctx context.Context, query string) (Result, uint16, error)
	PrepareQuery(ctx context.Context, query string, args ...interface{}) (Result, uint16, error)
	PrepareExecute(ctx context.Context, query string, args ...interface{}) (Result, uint16, error)
	PrepareExecuteStmt(ctx context.Context, stmt *Stmt) (Result, uint16, error)
	XAStart(ctx context.Context, sql string) (Tx, Result, error)
}

DBGroupExecutor prepare a query, execute the statement, and then close the statement.

type DBGroupTx added in v0.5.0

type DBGroupTx interface {
	Begin(ctx context.Context, executor DBGroupExecutor) (Tx, error)
	Query(ctx context.Context, query string) (Result, uint16, error)
	Execute(ctx context.Context, stmt ast.StmtNode, args ...interface{}) (Result, uint16, error)
	Commit(ctx context.Context) (result Result, err error)
	Rollback(ctx context.Context) (result Result, err error)
}

func ExtractDBGroupTx added in v0.5.0

func ExtractDBGroupTx(ctx context.Context) DBGroupTx

ExtractDBGroupTx .

type DBListener

type DBListener interface {
	Listener
	SetExecutor(executor Executor)
}

type DBManager

type DBManager interface {
	GetDB(name string) DB
}

type DBPostFilter

type DBPostFilter interface {
	Filter
	PostHandle(ctx context.Context, result Result, err error) error
}

DBPostFilter ...

type DBPreFilter

type DBPreFilter interface {
	Filter
	PreHandle(ctx context.Context) error
}

DBPreFilter ...

type DBStatus

type DBStatus uint8
const (
	Unknown DBStatus = iota
	Running
)

type DistributedTransactionManager added in v0.4.0

type DistributedTransactionManager interface {
	Begin(ctx context.Context, transactionName string, timeout int32) (string, error)
	Commit(ctx context.Context, xid string) (api.GlobalSession_GlobalStatus, error)
	Rollback(ctx context.Context, xid string) (api.GlobalSession_GlobalStatus, error)
	BranchRegister(ctx context.Context, in *api.BranchRegisterRequest) (string, int64, error)
	BranchReport(ctx context.Context, branchID string, status api.BranchSession_BranchStatus) error
	ReleaseLockKeys(ctx context.Context, resourceID string, lockKeys []string) (bool, error)
	IsLockable(ctx context.Context, resourceID, lockKey string) (bool, error)
	IsLockableWithXID(ctx context.Context, resourceID, lockKey, xid string) (bool, error)
	ListDeadBranchSessions(ctx context.Context) ([]*api.BranchSession, error)
	IsMaster() bool
}

type Executor

type Executor interface {
	GetPreFilters() []DBPreFilter

	GetPostFilters() []DBPostFilter

	ExecuteMode() config.ExecuteMode

	ProcessDistributedTransaction() bool

	InLocalTransaction(ctx context.Context) bool

	InGlobalTransaction(ctx context.Context) bool

	ExecuteUseDB(ctx context.Context, db string) error

	ExecuteFieldList(ctx context.Context, table, wildcard string) ([]Field, error)

	ExecutorComQuery(ctx context.Context, sql string) (Result, uint16, error)

	ExecutorComStmtExecute(ctx context.Context, stmt *Stmt) (Result, uint16, error)

	ConnectionClose(ctx context.Context)
}

Executor ...

type Field

type Field interface {
	FiledName() string

	TableName() string

	DataBaseName() string

	TypeDatabaseName() string
}

type Filter

type Filter interface {
	GetKind() string
}

type FilterFactory

type FilterFactory interface {
	NewFilter(appid string, config map[string]interface{}) (Filter, error)
}

type HttpPostFilter

type HttpPostFilter interface {
	Filter
	PostHandle(ctx context.Context, fastHttpCtx *fasthttp.RequestCtx) error
}

type HttpPreFilter

type HttpPreFilter interface {
	Filter
	PreHandle(ctx context.Context, fastHttpCtx *fasthttp.RequestCtx) error
}

type Listener

type Listener interface {
	Listen()
	Close()
}

type Optimizer

type Optimizer interface {
	// Optimize optimizes the sql with arguments then returns a Plan.
	Optimize(ctx context.Context, stmt ast.StmtNode, args ...interface{}) (Plan, error)
}

Optimizer represents a sql statement optimizer which can be used to create QueryPlan or ExecPlan.

type Plan

type Plan interface {
	// Execute executes the current Plan.
	Execute(ctx context.Context, hints ...*ast.TableOptimizerHint) (Result, uint16, error)
}

Plan represents a plan for query/execute command.

type Result

type Result interface {
	// LastInsertId returns the database's auto-generated ID
	// after, for example, an INSERT into a table with primary
	// key.
	LastInsertId() (uint64, error)

	// RowsAffected returns the number of rows affected by the
	// query.
	RowsAffected() (uint64, error)
}

Result is the result of a query execution.

type Row

type Row interface {
	// Columns returns the names of the columns. The number of
	// columns of the result is inferred from the length of the
	// slice. If a particular column name isn't known, an empty
	// string should be returned for that entry.
	Columns() []string

	Fields() []Field

	// Data
	Data() []byte

	Decode() ([]*Value, error)
}

Rows is an iterator over an executed query's results.

type SequenceGenerator added in v0.5.0

type SequenceGenerator interface {
	NextID() (int64, error)
}

type Stmt

type Stmt struct {
	StatementID      uint32
	HasLongDataParam bool
	SqlText          string
	ParamsCount      uint16
	ParamData        []byte
	ParamsType       []int32
	ColumnNames      []string
	BindVars         map[string]interface{}
	StmtNode         ast.StmtNode
}

Stmt is a buffer used for store prepare statement meta data

func PrepareStmt

func PrepareStmt(ctx context.Context) *Stmt

PrepareStmt extracts prepare stmt

type Tx

type Tx interface {
	Query(ctx context.Context, query string) (Result, uint16, error)
	QueryDirectly(query string) (Result, uint16, error)
	ExecuteStmt(ctx context.Context, stmt *Stmt) (Result, uint16, error)
	ExecuteSql(ctx context.Context, sql string, args ...interface{}) (Result, uint16, error)
	ExecuteSqlDirectly(sql string, args ...interface{}) (Result, uint16, error)
	Commit(ctx context.Context) (Result, error)
	Rollback(ctx context.Context, stmt *ast.RollbackStmt) (Result, error)
	ReleaseSavepoint(ctx context.Context, savepoint string) (result Result, err error)
	XAPrepare(ctx context.Context, sql string) (Result, error)
}

type Value

type Value struct {
	Typ   constant.FieldType
	Flags uint
	Len   int
	Val   interface{}
	Raw   []byte
}

Jump to

Keyboard shortcuts

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