proto

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotSequenceType  = errors.New("sequence type not found")
	ErrorNotFoundSequence = errors.New("sequence instance not found")
)

Functions

func BuildAutoIncrementName

func BuildAutoIncrementName(table string) string

func RegisterSchemaLoader

func RegisterSchemaLoader(l SchemaLoader)

func RegisterSequence

func RegisterSequence(name string, supplier SequenceSupplier)

RegisterSequence Register a Sequence plugin

func RegisterSequenceManager

func RegisterSequenceManager(l SequenceManager)

Types

type Callable

type Callable interface {
	// Call executes a sql.
	Call(ctx context.Context, sql string, args ...interface{}) (res Result, warn uint16, err error)
	// CallFieldList lists fields.
	CallFieldList(ctx context.Context, table, wildcard string) ([]Field, error)
}

Callable represents sql caller.

type ColumnMetadata

type ColumnMetadata struct {
	Name string
	// TODO int32
	DataType      string
	Ordinal       string
	PrimaryKey    bool
	Generated     bool
	CaseSensitive bool
}

type Context

type Context struct {
	context.Context

	Tenant        string
	Schema        string
	ServerVersion string

	ConnectionID uint32

	// sql Data
	Data []byte

	Stmt *Stmt
}

Context is used to carry context objects

func (Context) GetArgs

func (c Context) GetArgs() []interface{}

func (Context) GetQuery

func (c Context) GetQuery() string

type DB

type DB interface {
	io.Closer
	Callable
	// ID returns the unique id.
	ID() string
	// IdleTimeout returns the idle timeout.
	IdleTimeout() time.Duration
	// MaxCapacity returns the max capacity.
	MaxCapacity() int
	// Capacity returns the capacity.
	Capacity() int
	// Weight returns the weight.
	Weight() Weight
	// SetCapacity sets the capacity.
	SetCapacity(capacity int) error
	// SetMaxCapacity sets the max capacity.
	SetMaxCapacity(maxCapacity int) error
	// SetIdleTimeout sets the idle timeout.
	SetIdleTimeout(idleTimeout time.Duration) error
	// SetWeight sets the weight.
	SetWeight(weight Weight) error
}

DB represents an accessor to physical mysql, just like sql.DB.

type Dataset

type Dataset interface {
	io.Closer

	// Fields returns the fields of Dataset.
	Fields() ([]Field, error)

	// Next returns the next row.
	Next() (Row, error)
}

type EnhancedSequence

type EnhancedSequence interface {
	Sequence
	// Start start sequence instance.
	Start(ctx context.Context, option SequenceConfig) error
	// CurrentVal get sequence current id.
	CurrentVal() int64
	// Stop stops sequence.
	Stop() error
}

EnhancedSequence represents a global unique id generator.

type Executable

type Executable interface {
	// Execute executes the sql context.
	Execute(ctx *Context) (result Result, warn uint16, err error)
}

Executable represents an executor which can send sql request.

type Executor

type Executor interface {
	ProcessDistributedTransaction() bool
	InLocalTransaction(ctx *Context) bool
	InGlobalTransaction(ctx *Context) bool
	ExecuteUseDB(ctx *Context) error
	ExecuteFieldList(ctx *Context) ([]Field, error)
	ExecutorComQuery(ctx *Context) (Result, uint16, error)
	ExecutorComStmtExecute(ctx *Context) (Result, uint16, error)
	ConnectionClose(ctx *Context)
}

Executor

type Field

type Field interface {
	// Name returns the name or alias of the column.
	Name() string

	// DecimalSize returns the scale and precision of a decimal type.
	// If not applicable or if not supported ok is false.
	DecimalSize() (precision, scale int64, ok bool)

	// ScanType returns a Go type suitable for scanning into using Rows.Scan.
	// If a driver does not support this property ScanType will return
	// the type of empty interface.
	ScanType() reflect.Type

	// Length returns the column type length for variable length column types such
	// as text and binary field types. If the type length is unbounded the value will
	// be math.MaxInt64 (any database limits will still apply).
	// If the column type is not variable length, such as an int, or if not supported
	// by the driver ok is false.
	Length() (length int64, ok bool)

	// Nullable reports whether the column may be null.
	// If a driver does not support this property ok will be false.
	Nullable() (nullable, ok bool)

	// DatabaseTypeName returns the database system name of the column type. If an empty
	// string is returned, then the driver type name is not supported.
	// Consult your driver documentation for a list of driver data types. Length specifiers
	// are not included.
	// Common type names include "VARCHAR", "TEXT", "NVARCHAR", "DECIMAL", "BOOL",
	// "INT", and "BIGINT".
	DatabaseTypeName() string
}

Field contains the name and type of column, it follows sql.ColumnType.

type IndexMetadata

type IndexMetadata struct {
	Name string
}

type KeyedRow

type KeyedRow interface {
	Row
	// Fields returns the fields of row.
	Fields() []Field
	// Get returns the value of column name.
	Get(name string) (Value, error)
}

KeyedRow represents row with fields.

type Listener

type Listener interface {
	SetExecutor(executor Executor)
	Listen()
	Close()
}

type Optimizer

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

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

type Plan

type Plan interface {
	// Type returns the type of Plan.
	Type() PlanType
	// ExecIn executes the current Plan.
	ExecIn(ctx context.Context, conn VConn) (Result, error)
}

Plan represents a plan for query/execute command.

type PlanType

type PlanType uint8

PlanType represents the type of Plan.

const (
	PlanTypeQuery PlanType = iota // QUERY
	PlanTypeExec                  // EXEC
)

type ResourceManager

type ResourceManager interface {
	GetMasterResourcePool(name string) *pools.ResourcePool
	GetSlaveResourcePool(name string) *pools.ResourcePool
	GetMetaResourcePool(name string) *pools.ResourcePool
}

type Result

type Result interface {
	// Dataset returns the Dataset.
	Dataset() (Dataset, error)

	// 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 {
	io.WriterTo
	IsBinary() bool

	// Length returns the length of Row.
	Length() int

	// Scan scans the Row to values.
	Scan(dest []Value) error
}

Row represents a row data from a result set.

type RuntimeCtxKey

type RuntimeCtxKey = struct{}

type SchemaLoader

type SchemaLoader interface {
	// Load loads the schema.
	Load(ctx context.Context, schema string, table []string) (map[string]*TableMetadata, error)
}

SchemaLoader represents a schema discovery.

func LoadSchemaLoader

func LoadSchemaLoader() SchemaLoader

type Sequence

type Sequence interface {
	// Acquire generates a next value in int64.
	Acquire(ctx context.Context) (int64, error)
	Reset() error
	Update() error
}

Sequence represents a global unique id generator.

type SequenceConfig

type SequenceConfig struct {
	Name   string
	Type   string
	Option map[string]string
}

type SequenceManager

type SequenceManager interface {
	// CreateSequence creates one sequence instance
	CreateSequence(ctx context.Context, tenant, schema string, opt SequenceConfig) (Sequence, error)
	// GetSequence gets sequence instance by name
	GetSequence(ctx context.Context, tenant, schema, name string) (Sequence, error)
}

SequenceManager represents the factory to create a Sequence by table name.

func LoadSequenceManager

func LoadSequenceManager() SequenceManager

type SequenceSupplier

type SequenceSupplier func() EnhancedSequence

SequenceSupplier Create the creator of Sequence

func GetSequenceSupplier

func GetSequenceSupplier(name string) (SequenceSupplier, bool)

GetSequenceSupplier returns SequenceSupplier.

type Stmt

type Stmt struct {
	StatementID uint32
	PrepareStmt string
	ParamsCount uint16
	ParamsType  []int32
	ColumnNames []string
	BindVars    map[string]interface{}
	Hints       []*hint.Hint
	StmtNode    ast.StmtNode
}

Stmt is a buffer used for store prepare statement metadata.

type TableMetadata

type TableMetadata struct {
	Name              string
	Columns           map[string]*ColumnMetadata
	Indexes           map[string]*IndexMetadata
	ColumnNames       []string
	PrimaryKeyColumns []string
}

func NewTableMetadata

func NewTableMetadata(name string, columnMetadataList []*ColumnMetadata, indexMetadataList []*IndexMetadata) *TableMetadata

type Tx

type Tx interface {
	Executable
	VConn
	// ID returns the unique transaction id.
	ID() int64
	// Commit commits current transaction.
	Commit(ctx context.Context) (Result, uint16, error)
	// Rollback rollbacks current transaction.
	Rollback(ctx context.Context) (Result, uint16, error)
}

Tx represents transaction.

type VConn

type VConn interface {
	// Query requests a query command.
	Query(ctx context.Context, db string, query string, args ...interface{}) (Result, error)
	// Exec requests a exec command
	Exec(ctx context.Context, db string, query string, args ...interface{}) (Result, error)
}

VConn represents a virtual connection which can be used to query/exec from a db.

type Value

type Value interface{}

Value represents the cell value of Row.

type Weight

type Weight struct {
	R int32 // read weight
	W int32 // write weight
}

Weight represents the read/write weight info.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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