vtsql

package
v0.21.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Credentials Credentials
	// CredentialsPath is used only to power vtadmin debug endpoints; there may
	// be a better way where we don't need to put this in the config, because
	// it's not really an "option" in normal use.
	CredentialsPath string

	Cluster         *vtadminpb.Cluster
	ResolverOptions *resolver.Options
	// contains filtered or unexported fields
}

Config represents the options that modify the behavior of a vtqsl.VTGateProxy.

func Parse

func Parse(cluster *vtadminpb.Cluster, disco discovery.Discovery, args []string) (*Config, error)

Parse returns a new config with the given cluster ID and name, after attempting to parse the command-line pflags into that Config. See (*Config).Parse() for more details.

func (*Config) Parse

func (c *Config) Parse(args []string) error

Parse reads options specified as command-line pflags (--key=value, note the double-dash!) into a vtsql.Config. It is meant to be called from (*cluster.Cluster).New().

type ConfigOption added in v0.14.0

type ConfigOption func(cfg *Config) *Config

ConfigOption is a function that mutates a Config. It should return the same Config structure, in a builder-pattern style.

func WithDialFunc added in v0.14.0

func WithDialFunc(f func(c vitessdriver.Configuration) (*sql.DB, error)) ConfigOption

WithDialFunc returns a ConfigOption that applies the given dial function to a Config.

It is used to support dependency injection in tests, and needs to be exported for higher-level tests (for example, package vtadmin/cluster).

type Credentials

type Credentials interface {
	// GetEffectiveUsername returns the username on whose behalf the DB is
	// issuing queries.
	GetEffectiveUsername() string
	// GetUsername returns the immediate username for a DB connection.
	GetUsername() string
	credentials.PerRPCCredentials
}

Credentials defines the interface needed for vtsql properly connect to and query Vitess databases.

type DB

type DB interface {
	// ShowTablets executes `SHOW vitess_tablets` and returns the result.
	ShowTablets(ctx context.Context) (*sql.Rows, error)

	// Ping behaves like (*sql.DB).Ping.
	Ping() error
	// PingContext behaves like (*sql.DB).PingContext.
	PingContext(ctx context.Context) error

	// Close closes the underlying database connection. This is a no-op if
	// the DB has no current valid connection. It is safe to call repeatedly.
	//
	// Once closed, a DB is not safe for reuse.
	Close() error
}

DB defines the connection and query interface of vitess SQL queries used by VTAdmin clusters.

type StaticAuthCredentials

type StaticAuthCredentials struct {
	*grpcclient.StaticAuthClientCreds
	EffectiveUser string
}

StaticAuthCredentials augments a grpcclient.StaticAuthClientCreds with an effective username.

func (*StaticAuthCredentials) GetEffectiveUsername

func (creds *StaticAuthCredentials) GetEffectiveUsername() string

GetEffectiveUsername is part of the Credentials interface.

func (*StaticAuthCredentials) GetUsername

func (creds *StaticAuthCredentials) GetUsername() string

GetUsername is part of the Credentials interface.

type VTGateProxy

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

VTGateProxy is a proxy for creating and using database connections to vtgates in a Vitess cluster.

func New

func New(ctx context.Context, cfg *Config) (*VTGateProxy, error)

New returns a VTGateProxy to the given cluster. When Dial-ing, it will use the given discovery implementation to find a vtgate to connect to, and the given creds to dial the underlying gRPC connection, both of which are provided by the Config.

It does not open a connection to a vtgate; users must call Dial before first use.

func (*VTGateProxy) Close

func (vtgate *VTGateProxy) Close() error

Close is part of the DB interface and satisfies io.Closer.

func (*VTGateProxy) Debug added in v0.12.0

func (vtgate *VTGateProxy) Debug() map[string]any

Debug implements debug.Debuggable for VTGateProxy.

func (*VTGateProxy) Ping

func (vtgate *VTGateProxy) Ping() error

Ping is part of the DB interface.

func (*VTGateProxy) PingContext

func (vtgate *VTGateProxy) PingContext(ctx context.Context) error

PingContext is part of the DB interface.

func (*VTGateProxy) ShowTablets

func (vtgate *VTGateProxy) ShowTablets(ctx context.Context) (*sql.Rows, error)

ShowTablets is part of the DB interface.

Directories

Path Synopsis
Package fakevtsql provides an interface for mocking out sql.DB responses in tests that depend on a vtsql.DB instance.
Package fakevtsql provides an interface for mocking out sql.DB responses in tests that depend on a vtsql.DB instance.

Jump to

Keyboard shortcuts

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