Documentation
¶
Index ¶
- Variables
- func BuildAutoIncrementName(table string) string
- func CompareValue(a, b Value) int
- func RegisterFunc(name string, f Func)
- func RegisterSchemaLoader(l SchemaLoader)
- func RegisterSequence(name string, supplier SequenceSupplier)
- func RegisterSequenceManager(l SequenceManager)
- func ValidateFunction(ctx context.Context, f Func, strict bool) bool
- type Callable
- type ColumnMetadata
- type Context
- type ContextKeyEnableLocalComputation
- type ContextKeySQL
- type ContextKeySchema
- type ContextKeyServerVersion
- type ContextKeyTenant
- type ContextKeyTransientVariables
- type DB
- type Dataset
- type EnhancedSequence
- type Executable
- type Executor
- type Field
- type FrontConn
- type Func
- type FuncValuer
- type IndexMetadata
- type KeyedRow
- type Listener
- type NodeConn
- type Null
- type Optimizer
- type Plan
- type PlanType
- type Result
- type Row
- type RuntimeCtxKey
- type SchemaLoader
- type Sequence
- type SequenceConfig
- type SequenceManager
- type SequenceSupplier
- type Stmt
- type TableMetadata
- type Tx
- type VConn
- type Value
- func MustNewValue(input interface{}) Value
- func MustNewValueDecimalString(s string) Value
- func NewValue(input interface{}) (Value, error)
- func NewValueBool(b bool) Value
- func NewValueDecimal(d decimal.Decimal) Value
- func NewValueFloat64(v float64) Value
- func NewValueInt64(v int64) Value
- func NewValueString(s string) Value
- func NewValueTime(t time.Time) Value
- func NewValueTyped(origin Value, overwriteFamily ValueFamily) Value
- func NewValueUint64(v uint64) Value
- type ValueFamily
- type Valuer
- type VersionSupport
- type VersionedFunc
- type Weight
Constants ¶
This section is empty.
Variables ¶
var ( ErrorNotSequenceType = errors.New("sequence type not found") ErrorNotFoundSequence = errors.New("sequence instance not found") )
Functions ¶
func BuildAutoIncrementName ¶
func CompareValue ¶
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 ...Value) (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 ContextKeyEnableLocalComputation ¶
type ContextKeyEnableLocalComputation struct{}
type ContextKeySQL ¶
type ContextKeySQL struct{}
type ContextKeySchema ¶
type ContextKeySchema struct{}
type ContextKeyServerVersion ¶
type ContextKeyServerVersion struct{}
type ContextKeyTenant ¶
type ContextKeyTenant struct{}
type ContextKeyTransientVariables ¶
type ContextKeyTransientVariables struct{}
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
// NodeConn returns the node connection info.
NodeConn() NodeConn
// 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
// Variable returns the variable value.
Variable(ctx context.Context, name string) (interface{}, error)
}
DB represents an accessor to physical mysql, just like sql.DB.
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
// GetSequenceConfig get sequence config.
GetSequenceConfig() SequenceConfig
}
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, schema string) error
ExecuteFieldList(ctx *Context) ([]Field, error)
ExecutorComQuery(ctx *Context, callback func(Result, uint16, error) error) error
ExecutorComStmtExecute(ctx *Context) (Result, uint16, error)
ConnectionClose(ctx *Context)
}
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 FrontConn ¶
type FrontConn interface {
// ID returns connection id.
ID() uint32
// Schema returns the current schema.
Schema() string
// SetSchema sets the current schema.
SetSchema(schema string)
// Tenant returns the tenant.
Tenant() string
// SetTenant sets the tenant.
SetTenant(tenant string)
// TransientVariables returns the transient variables.
TransientVariables() map[string]Value
// SetTransientVariables sets the transient variables.
SetTransientVariables(v map[string]Value)
// CharacterSet returns the character set.
CharacterSet() uint8
// ServerVersion returns the server version.
ServerVersion() string
}
FrontConn represents a frontend connection.
APP ---> FRONTEND_CONN ---> ARANA ---> BACKEND_CONN ---> MySQL
type Func ¶
type Func interface {
// Apply call the current function.
Apply(ctx context.Context, inputs ...Valuer) (Value, error)
// NumInput returns the minimum number of inputs.
NumInput() int
}
Func represents a MySQL function.
func MustGetFunc ¶
MustGetFunc gets Func by given name, panic if missing.
type FuncValuer ¶
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 NodeConn ¶
type NodeConn struct {
Host string // connection host
Port int // connection port
UserName string // connection username
Password string // connection password
Database string // connection database
Weight string // connection weight
Parameters string // connection parameters
}
NodeConn represents the node connection info
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 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 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]Value
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() string
// 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 ...Value) (Result, error)
// Exec requests a exec command
Exec(ctx context.Context, db string, query string, args ...Value) (Result, error)
}
VConn represents a virtual connection which can be used to query/exec from a db.
type Value ¶
type Value interface {
fmt.Stringer
Family() ValueFamily
Float64() (float64, error)
Int64() (int64, error)
Uint64() (uint64, error)
Decimal() (decimal.Decimal, error)
Bool() (bool, error)
Time() (time.Time, error)
Less(than Value) bool
}
Value represents the cell value of Row.
func MustNewValue ¶
func MustNewValue(input interface{}) Value
func NewValueBool ¶
func NewValueDecimal ¶
func NewValueFloat64 ¶
func NewValueInt64 ¶
func NewValueString ¶
func NewValueTime ¶
func NewValueTyped ¶
func NewValueTyped(origin Value, overwriteFamily ValueFamily) Value
func NewValueUint64 ¶
type ValueFamily ¶
type ValueFamily uint8
const ( ValueFamilyString ValueFamily ValueFamilySign ValueFamilyUnsigned ValueFamilyFloat ValueFamilyDecimal ValueFamilyBool ValueFamilyTime ValueFamilyDuration // TODO: support HH:mm::ss, used by INTERVAL )
func (ValueFamily) IsNumberic ¶
func (v ValueFamily) IsNumberic() bool
func (ValueFamily) String ¶
func (v ValueFamily) String() string
type Valuer ¶
type Valuer interface {
// Value computes and returns the Value.
Value(ctx context.Context) (Value, error)
}
Valuer represents a generator or value.
func ToValuerWithError ¶
ToValuerWithError returns a Valuer which always returns an error. NOTICE: we don't usually use this method, it's only for testing!
type VersionSupport ¶
type VersionSupport interface {
// Version returns the version.
Version(ctx context.Context) (string, error)
}
VersionSupport provides the version string.
type VersionedFunc ¶
type VersionedFunc interface {
Func
// Versions returns the version range of current function.
Versions() semver.Range
}
VersionedFunc represents a MySQL function with versions. See this doc: https://dev.mysql.com/doc/refman/8.0/en/built-in-function-reference.html