db

package
v1.1.0-beta Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinResolveCluster func(*Loc, ConnectionType) (*Addr, error)

BuiltinResolveCluster to implement runtime polymorphism and resolve cyclic package dependency. state.SchemaGet will be assigned to in main.go and connectInfoGetFortest in db/open_test.go

View Source
var GetConnInfo = GetConnInfoByType

GetConnInfo is database address resolving function

View Source
var GetEnumerator = GetEnumeratorByType

GetEnumerator is database location enumerating function

View Source
var IsValidConn = IsValidConnByType

IsValidConn is database connection validator function that verifies connection is to the correct DB

View Source
var SQLMode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

SQLMode can be substituted by tests Difference from default value is ONLY_FULL_GROUP_BY removed, required by state SQL joins

Functions

func GetCurrentGTID

func GetCurrentGTID(addr *Addr) (string, error)

GetCurrentGTID returns current gtid set for the specified db address (host,port,user,password)

func GetCurrentGTIDForDB

func GetCurrentGTIDForDB(loc *Loc, inputType string) (string, error)

GetCurrentGTIDForDB return current gtid set for the db specified by db locator (cluster,service,db)

func GetPurgedGTID

func GetPurgedGTID(addr *Addr) (string, error)

GetPurgedGTID returns purged gtid set for the specified db address (host,port,user,password)

func IsValidConnByType

func IsValidConnByType(dbl *Loc, connType ConnectionType, addr *Addr, inputType string) bool

IsValidConnByType checks the validity of the connection to make sure connection is to the correct DB

func IsValidConnForTest

func IsValidConnForTest(_ *Loc, _ ConnectionType, _ *Addr, _ string) bool

IsValidConnForTest is DB connection validator for tests

func JSONServer

func JSONServer(js string) (*httptest.Server, map[string]json.RawMessage)

JSONServer starts a new server which serves json that's passed to it as an argument. The string should be json with a map of url->response. If the response is "error" then the server will return 500.

func Open

func Open(ci *Addr) (*sql.DB, error)

Open opens database connection by given address

func OpenModeType

func OpenModeType(ci *Addr, drv, mode string) (*sql.DB, error)

OpenModeType opens database connection by given address

func OpenService

func OpenService(dbl *Loc, substDB string, inputType string) (*sql.DB, error)

OpenService resolves db information for database and connects to that db. substDB can be passed to override the db resolved by database locator.

Types

type Addr

type Addr struct {
	Name string `json:"name"`
	Host string `json:"host"`
	Port uint16 `json:"port"`
	User string `json:"user"`
	Pwd  string `json:"pwd"`
	DB   string `json:"db"`
}

Addr contains information required to connect to DB

func GetConnInfoByType

func GetConnInfoByType(dbl *Loc, connType ConnectionType, inputType string) (*Addr, error)

GetConnInfoByType returns DB connection info by type of DB node

func GetConnInfoForTest

func GetConnInfoForTest(dbl *Loc, connType ConnectionType, inputType string) (*Addr, error)

GetConnInfoForTest return address of local MySQL used by tests

func (*Addr) Log

func (a *Addr) Log() log.Logger

Log returns logger with Addr fields

type BuiltinEnumerator

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

BuiltinEnumerator implements a db location enumerator for MySQL

func (*BuiltinEnumerator) Next

func (e *BuiltinEnumerator) Next() bool

Next is used to check if anymore values can be returned by the enumerator

func (*BuiltinEnumerator) Reset

func (e *BuiltinEnumerator) Reset()

Reset resets the enumerator to the starting point

func (*BuiltinEnumerator) Value

func (e *BuiltinEnumerator) Value() *Loc

Value returns the current value from the enumerator

type BuiltinResolver

type BuiltinResolver struct {
}

BuiltinResolver resolves MySQL connection info for SOA databases using Nemo

func (*BuiltinResolver) GetEnumerator

func (r *BuiltinResolver) GetEnumerator(ctx context.Context, svc, cluster, sdb, table string) (Enumerator, error)

GetEnumerator returns an enumerator for db location info fetched from Nemo

func (*BuiltinResolver) GetInfo

func (r *BuiltinResolver) GetInfo(ctx context.Context, dbl *Loc, connType ConnectionType) (*Addr, error)

GetInfo returns MySQL connection info

func (*BuiltinResolver) IsValidConn

func (r *BuiltinResolver) IsValidConn(ctx context.Context, dbl *Loc, connType ConnectionType, addr *Addr) bool

IsValidConn checks the validity of the connection to make sure connection is to the correct MySQL DB

type ConnectionType

type ConnectionType int

ConnectionType is used as enum to represent connection types

const (
	// Master is the type corresponding to a master or a leader
	Master ConnectionType = iota

	// Slave is the type corresponding to a slave or a follower
	Slave
)

func (ConnectionType) String

func (c ConnectionType) String() string

type Enumerator

type Enumerator interface {
	Value() *Loc
	Next() bool
	Reset()
}

Enumerator defines an iterator that allows iterating over db locations

func GetEnumeratorByType

func GetEnumeratorByType(svc, cluster, sdb, table, inputType string) (Enumerator, error)

GetEnumeratorByType returns a DB location enumerator depending on the input type

func GetEnumeratorForTest

func GetEnumeratorForTest(svc, cluster, sdb, table, inputType string) (Enumerator, error)

GetEnumeratorForTest return db location info enumerator used by tests

type Loc

type Loc struct {
	Cluster string
	Service string
	Name    string
}

Loc contains information related to database location

func (*Loc) LogFields

func (d *Loc) LogFields() log.Logger

LogFields provides a logger that logs messages with Loc fields

type Resolver

type Resolver interface {
	GetInfo(context.Context, *Loc, ConnectionType) (*Addr, error)
	GetEnumerator(context.Context, string, string, string, string) (Enumerator, error)
	IsValidConn(ctx context.Context, dbl *Loc, connType ConnectionType, addr *Addr) bool
}

Resolver defines a MySQL connection info resolver

func NewBuiltinResolver

func NewBuiltinResolver() Resolver

NewBuiltinResolver returns a new resolver for resolving connection info using Nemo

func NewResolver

func NewResolver(inputType string) (Resolver, error)

NewResolver returns a MySQL connection info resolver depending on the input type

type TableLoc

type TableLoc struct {
	Service string
	Cluster string
	DB      string
	Table   string
	Input   string
	Output  string
	Version int
}

TableLoc - table location

Jump to

Keyboard shortcuts

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