sqldb

package
v2.0.0-alpha2+incompat... Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2015 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package sqldb defines an interface for low level db connection.

Package sqldb defines an interface for low level db connection

Index

Constants

This section is empty.

Variables

View Source
var DefaultDB string

DefaultDB decides the default db connection.

Functions

func Register

func Register(name string, fn NewConnFunc)

Register a db connection.

Types

type Conn

type Conn interface {
	// ExecuteFetch executes the query on the connection
	ExecuteFetch(query string, maxrows int, wantfields bool) (*proto.QueryResult, error)
	// ExecuteFetchMap returns a map from column names to cell data for a query
	// that should return exactly 1 row.
	ExecuteFetchMap(query string) (map[string]string, error)
	// ExecuteStreamFetch starts a streaming query to db server. Use FetchNext
	// on the Connection until it returns nil or error
	ExecuteStreamFetch(query string) error
	// Close closes the db connection
	Close()
	// IsClosed returns if the connection was ever closed
	IsClosed() bool
	// CloseResult finishes the result set
	CloseResult()
	// Shutdown invokes the low-level shutdown call on the socket associated with
	// a connection to stop ongoing communication.
	Shutdown()
	// Fields returns the current fields description for the query
	Fields() []proto.Field
	// ID returns the connection id.
	ID() int64
	// FetchNext returns the next row for a query
	FetchNext() ([]sqltypes.Value, error)
	// ReadPacket reads a raw packet from the connection.
	ReadPacket() ([]byte, error)
	// SendCommand sends a raw command to the db server.
	SendCommand(command uint32, data []byte) error
	// GetCharset returns the current numerical values of the per-session character
	// set variables.
	GetCharset() (cs proto.Charset, err error)
	// SetCharset changes the per-session character set variables.
	SetCharset(cs proto.Charset) error
}

Conn defines the behavior for the low level db connection

func Connect

func Connect(params ConnParams) (Conn, error)

Connect returns a sqldb.Conn using the default connection creation function.

type ConnParams

type ConnParams struct {
	Host       string `json:"host"`
	Port       int    `json:"port"`
	Uname      string `json:"uname"`
	Pass       string `json:"pass"`
	DbName     string `json:"dbname"`
	UnixSocket string `json:"unix_socket"`
	Charset    string `json:"charset"`
	Flags      uint64 `json:"flags"`

	// the following flags are only used for 'Change Master' command
	// for now (along with flags |= 2048 for CLIENT_SSL)
	SslCa     string `json:"ssl_ca"`
	SslCaPath string `json:"ssl_ca_path"`
	SslCert   string `json:"ssl_cert"`
	SslKey    string `json:"ssl_key"`
}

ConnParams contains all the parameters to use to connect to mysql

type NewConnFunc

type NewConnFunc func(params ConnParams) (Conn, error)

NewConnFunc is a factory method that creates a Conn instance using given ConnParams.

type SqlError

type SqlError struct {
	Num     int
	Message string
	Query   string
}

SqlError is the error structure returned from calling a db library function

func NewSqlError

func NewSqlError(number int, format string, args ...interface{}) *SqlError

NewSqlError returns a new SqlError

func (*SqlError) Error

func (se *SqlError) Error() string

Error implements the error interface

func (*SqlError) Number

func (se *SqlError) Number() int

Number returns the internal mysql error code

Jump to

Keyboard shortcuts

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