mysql

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// PackageName is the package name.
	PackageName = "go-mysql"
)
View Source
const (
	Version = "v1.0.4"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthHandler

type AuthHandler interface {
	vitessmy.AuthServer
}

A AuthHandler is an interface used for the user authentication.

func NewDefaultAuthHandler

func NewDefaultAuthHandler() AuthHandler

NewDefaultAuthHandler returns a non authentication handler.

type BaseExecutor

type BaseExecutor struct {
}

BaseExecutor is a stub listener to implement only target executor functions.

func NewBaseExecutor

func NewBaseExecutor() *BaseExecutor

NewBaseExecutor returns an in-memory executorinstance.

func (*BaseExecutor) AlterDatabase

func (executor *BaseExecutor) AlterDatabase(conn *Conn, stmt *query.Database) (*Result, error)

AlterDatabase should handle a ALTER database statement.

func (*BaseExecutor) AlterTable

func (executor *BaseExecutor) AlterTable(conn *Conn, stmt *query.Schema) (*Result, error)

AlterTable should handle a ALTER table statement.

func (*BaseExecutor) Begin added in v1.0.5

func (executor *BaseExecutor) Begin(conn *Conn, stmt *query.Begin) (*Result, error)

Begin should handle a BEGIN statement.

func (*BaseExecutor) Commit added in v1.0.5

func (executor *BaseExecutor) Commit(conn *Conn, stmt *query.Commit) (*Result, error)

Commit should handle a COMMIT statement.

func (*BaseExecutor) CreateDatabase

func (executor *BaseExecutor) CreateDatabase(conn *Conn, stmt *query.Database) (*Result, error)

CreateDatabase should handle a CREATE database statement.

func (*BaseExecutor) CreateTable

func (executor *BaseExecutor) CreateTable(conn *Conn, stmt *query.Schema) (*Result, error)

CreateTable should handle a CREATE table statement.

func (*BaseExecutor) Delete

func (executor *BaseExecutor) Delete(conn *Conn, stmt *query.Delete) (*Result, error)

Delete should handle a DELETE statement.

func (*BaseExecutor) DropDatabase

func (executor *BaseExecutor) DropDatabase(conn *Conn, stmt *query.Database) (*Result, error)

DropDatabase should handle a DROP database statement.

func (*BaseExecutor) DropTable

func (executor *BaseExecutor) DropTable(conn *Conn, stmt *query.Schema) (*Result, error)

DropTable should handle a DROP table statement.

func (*BaseExecutor) Insert

func (executor *BaseExecutor) Insert(conn *Conn, stmt *query.Insert) (*Result, error)

Insert should handle a INSERT statement.

func (*BaseExecutor) RenameTable

func (executor *BaseExecutor) RenameTable(conn *Conn, stmt *query.Schema) (*Result, error)

RenameTable should handle a RENAME table statement.

func (*BaseExecutor) Rollback added in v1.0.5

func (executor *BaseExecutor) Rollback(conn *Conn, stmt *query.Rollback) (*Result, error)

Rollback should handle a ROLLBACK statement.

func (*BaseExecutor) Select

func (executor *BaseExecutor) Select(conn *Conn, stmt *query.Select) (*Result, error)

Select should handle a SELECT statement.

func (*BaseExecutor) ShowDatabases

func (executor *BaseExecutor) ShowDatabases(conn *Conn) (*Result, error)

ShowDatabases should handle a SHOW DATABASES statement.

func (*BaseExecutor) ShowTables

func (executor *BaseExecutor) ShowTables(conn *Conn, database string) (*Result, error)

ShowTables should handle a SHOW TABLES statement.

func (*BaseExecutor) TruncateTable

func (executor *BaseExecutor) TruncateTable(conn *Conn, stmt *query.Schema) (*Result, error)

TruncateTable should handle a TRUNCATE table statement.

func (*BaseExecutor) Update

func (executor *BaseExecutor) Update(conn *Conn, stmt *query.Update) (*Result, error)

Update should handle a UPDATE statement.

type BindVariable

type BindVariable = vitesspq.BindVariable

BindVariable represents a single bind variable.

type Client

type Client struct {
	*Config
	// contains filtered or unexported fields
}

Client represents a client for MySQL server.

func NewClient

func NewClient() *Client

NewClient returns a client instance.

func (*Client) Close

func (client *Client) Close() error

Close closes opens a database specified by the internal configuration.

func (*Client) Open

func (client *Client) Open() error

Open opens a database specified by the internal configuration.

func (*Client) Query

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

Query executes a query that returns rows.

type Config

type Config struct {
	Address  string
	Port     int
	Database string
}

Config stores server configuration parammeters.

func NewDefaultConfig

func NewDefaultConfig() *Config

NewDefaultConfig returns a default configuration instance.

func (*Config) SetAddress added in v1.0.0

func (config *Config) SetAddress(host string)

SetAddress sets a listen address.

func (*Config) SetDatabase

func (config *Config) SetDatabase(db string)

SetDatabase sets a host database.

func (*Config) SetPort

func (config *Config) SetPort(port int)

SetPort sets a listen port.

type Conn

type Conn struct {
	*vitessmy.Conn

	sync.Map
	tracer.Context
	// contains filtered or unexported fields
}

Conn represents a connection of MySQL binary protocol.

func NewConnWith added in v1.0.2

func NewConnWith(ctx tracer.Context, c *vitessmy.Conn) *Conn

NewConnWith returns a connection with a raw connection.

func (*Conn) Database

func (conn *Conn) Database() string

Database returns the current selected database in the connection.

func (*Conn) ID added in v0.9.2

func (conn *Conn) ID() uint32

ID returns the creation ID of the connection.

func (*Conn) SetDatabase added in v0.9.2

func (conn *Conn) SetDatabase(name string)

SetDatabase sets th selected database to the connection.

func (*Conn) SetDeadline added in v1.0.5

func (conn *Conn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadlines associated with the connection.

func (*Conn) SetReadDeadline added in v1.0.5

func (conn *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls.

func (*Conn) SetSpanContext added in v1.0.1

func (conn *Conn) SetSpanContext(span tracer.Context)

SetSpanContext sets the tracer span context to the connection.

func (*Conn) SetWriteDeadline added in v1.0.5

func (conn *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls.

func (*Conn) SpanContext added in v1.0.1

func (conn *Conn) SpanContext() tracer.Context

SpanContext returns the tracer span context of the connection.

func (*Conn) Timestamp

func (conn *Conn) Timestamp() time.Time

Timestamp returns the creation time of the connection.

func (*Conn) UUID added in v1.0.4

func (conn *Conn) UUID() uuid.UUID

UUID returns the UUID of the connection.

type ConnMap

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

ConnMap represents a connection map.

func NewConnMap

func NewConnMap() ConnMap

NewConnMap returns a connection map.

func (ConnMap) AddConn

func (cm ConnMap) AddConn(c *Conn)

AddConn adds the specified connection.

func (ConnMap) DeleteConnByUID

func (cm ConnMap) DeleteConnByUID(cid uint32)

DeleteConnByUID deletes the specified connection by the connection ID.

func (ConnMap) GetConnByUID

func (cm ConnMap) GetConnByUID(cid uint32) (*Conn, bool)

GetConnByUID returns a connection and true when the specified connection exists by the connection ID, otherwise nil and false.

func (ConnMap) Length

func (cm ConnMap) Length() int

Length returns the included connection count.

type DAOExecutor

type DAOExecutor interface {
	// ShowDatabases should handle a SHOW DATABASES statement.
	ShowDatabases(*Conn) (*Result, error)
	// ShowTables should handle a SHOW TABLES statement.
	ShowTables(*Conn, string) (*Result, error)
}

DAOExecutor defines a executor interface for DAO (Database Administration Operations).

type DCOExecutor

type DCOExecutor interface {
}

DCOExecutor defines a executor interface for DCO (Data Control Operations).

type DDOExecutor

type DDOExecutor interface {
	// CreateDatabase should handle a CREATE database statement.
	CreateDatabase(*Conn, *query.Database) (*Result, error)
	// AlterDatabase should handle a ALTER database statement.
	AlterDatabase(*Conn, *query.Database) (*Result, error)
	// DropDatabase should handle a DROP database statement.
	DropDatabase(*Conn, *query.Database) (*Result, error)
	// CreateTable should handle a CREATE table statement.
	CreateTable(*Conn, *query.Schema) (*Result, error)
	// AlterTable should handle a ALTER table statement.
	AlterTable(*Conn, *query.Schema) (*Result, error)
	// DropTable should handle a DROP table statement.
	DropTable(*Conn, *query.Schema) (*Result, error)
	// RenameTable should handle a RENAME table statement.
	RenameTable(*Conn, *query.Schema) (*Result, error)
	// TruncateTable should handle a TRUNCATE table statement.
	TruncateTable(*Conn, *query.Schema) (*Result, error)
}

DDOExecutor defines a executor interface for DDO (Data Definition Operations).

type DMOExecutor

type DMOExecutor interface {
	// Insert should handle a INSERT statement.
	Insert(*Conn, *query.Insert) (*Result, error)
	// Update should handle a UPDATE statement.
	Update(*Conn, *query.Update) (*Result, error)
	// Delete should handle a DELETE statement.
	Delete(*Conn, *query.Delete) (*Result, error)
	// Select should handle a SELECT statement.
	Select(*Conn, *query.Select) (*Result, error)
}

DMOExecutor defines a executor interface for DMO (Data Manipulation Operations).

type Field

type Field = vitesspq.Field

Field represents a field.

type Listener

type Listener struct {
	*vitessmy.Listener
}

Listener is the MySQL server protocol listener.

func NewListener

func NewListener(protocol, address string, authServer AuthHandler, handler QueryHandler, connReadTimeout time.Duration, connWriteTimeout time.Duration, proxyProtocol bool) (*Listener, error)

NewListener creates a new listener.

type MySQLClient

type MySQLClient struct {
	*Config
	// contains filtered or unexported fields
}

Client represents a client for MySQL server.

func NewMySQLClient

func NewMySQLClient() *MySQLClient

NewMySQLClient returns a client instance.

func (*MySQLClient) Close

func (client *MySQLClient) Close() error

Close closes opens a database specified by the internal configuration.

func (*MySQLClient) Open

func (client *MySQLClient) Open(dbName string) error

Open opens a database specified by the internal configuration.

func (*MySQLClient) Query

func (client *MySQLClient) Query(query string, args ...interface{}) (driver.Rows, error)

Query executes a query that returns rows. nolint: staticcheck

type PrepareData

type PrepareData = vitessmy.PrepareData

PrepareData is a buffer used for store prepare statement meta data.

type QueryExecutor

type QueryExecutor interface {
	DDOExecutor
	DMOExecutor
	DCOExecutor
	DAOExecutor
	TCLExecutor
}

QueryExecutor represents an interface to execute all SQL queries.

type QueryHandler

type QueryHandler interface {
	vitessmy.Handler
}

A QueryHandler is an interface used for the request queries.

type Result

type Result = vitessst.Result

Result represents a query result.

func NewResult

func NewResult() *Result

NewResult returns a successful result without any data.

func NewResultWithRows

func NewResultWithRows(db *query.Database, schema *query.Schema, rows *query.Rows) (*Result, error)

NewResultWithRows returns a successful result with the specified rows.

func NewResultWithRowsAffected

func NewResultWithRowsAffected(n uint64) *Result

NewResultWithRowsAffected returns a successful result with the specified rows affected count.

type Server

type Server struct {
	tracer.Tracer
	AuthHandler
	QueryHandler
	*Config
	ConnMap
	// contains filtered or unexported fields
}

Server represents a MySQL-compatible server.

func NewServer

func NewServer() *Server

NewServer returns a new server instance.

func (*Server) ComInitDB

func (server *Server) ComInitDB(c *vitessmy.Conn, dbName string)

ComInitDB is called once at the beginning to set db name, and subsequently for every ComInitDB event.

func (*Server) ComPrepare

func (server *Server) ComPrepare(c *vitessmy.Conn, query string, bindVars map[string]*BindVariable) ([]*Field, error)

ComPrepare is called when a connection receives a prepared statement query.

func (*Server) ComQuery

func (server *Server) ComQuery(c *vitessmy.Conn, q string, callback func(*Result) error) error

ComQuery is called when a connection receives a query. nolint: exhaustive

func (*Server) ComResetConnection

func (server *Server) ComResetConnection(c *vitessmy.Conn)

ComResetConnection is called when the connection is reseted.

func (*Server) ComStmtExecute

func (server *Server) ComStmtExecute(c *vitessmy.Conn, prepare *PrepareData, callback func(*Result) error) error

ComStmtExecute is called when a connection receives a statement execute query.

func (*Server) ConnectionClosed

func (server *Server) ConnectionClosed(c *vitessmy.Conn)

ConnectionClosed is called when a connection is closed.

func (*Server) NewConnection

func (server *Server) NewConnection(c *vitessmy.Conn)

NewConnection is called when a connection is created.

func (*Server) Restart

func (server *Server) Restart() error

Restart restarts the server.

func (*Server) SetAuthHandler

func (server *Server) SetAuthHandler(h AuthHandler)

SetAuthHandler sets a user authentication handler.

func (*Server) SetQueryExecutor

func (server *Server) SetQueryExecutor(e QueryExecutor)

SetQueryExecutor sets a query executor.

func (*Server) SetTracer added in v0.9.4

func (server *Server) SetTracer(t tracer.Tracer)

SetTracer sets a tracing tracer.

func (*Server) Start

func (server *Server) Start() error

Start starts the server.

func (*Server) Stop

func (server *Server) Stop() error

Stop stops the server.

func (*Server) WarningCount

func (server *Server) WarningCount(c *vitessmy.Conn) uint16

WarningCount is called at the end of each query to obtain the value to be returned to the client in the EOF packet.

type TCLExecutor added in v1.0.5

type TCLExecutor interface {
	// Begin should handle a BEGIN statement.
	Begin(*Conn, *query.Begin) (*Result, error)
	// Commit should handle a COMMIT statement.
	Commit(*Conn, *query.Commit) (*Result, error)
	// Rollback should handle a ROLLBACK statement.
	Rollback(*Conn, *query.Rollback) (*Result, error)
}

TCLExecutor defines a executor interface for TXN (Transaction Operations).

type Value

type Value = vitessst.Value

Value represents a value.

func NewNullValue added in v0.9.2

func NewNullValue() Value

NULL represents the NULL value.

func NewValueWith added in v0.9.2

func NewValueWith(typ vitesspq.Type, val []byte) (Value, error)

NewValueWith builds a Value using typ and val. If the value and typ don't match, it returns an error.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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