mysql

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: May 22, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateDatabaseIfNotExists

func CreateDatabaseIfNotExists(ctx context.Context, sql SQLRunner, database, charset, collate string) error

CreateDatabaseIfNotExists creates a database if it doesn't already exist

func CreateUserIfNotExists

func CreateUserIfNotExists(ctx context.Context, sql SQLRunner,
	user, pass string, allowedHosts []string, permissions []mysqlv1alpha1.MysqlPermission,
	resourceOptions corev1.ResourceList,
) error

CreateUserIfNotExists creates a user if it doesn't already exist and it gives it the specified permissions

func DropDatabase

func DropDatabase(ctx context.Context, sql SQLRunner, database string) error

DropDatabase deletes the database

func DropUser

func DropUser(ctx context.Context, sql SQLRunner, user, host string) error

DropUser removes a MySQL user if it exists, along with its privileges

func Escape

func Escape(sql string) string

Escape escapes a string

Types

type Config

type Config struct {
	User     string
	Password string
	Host     string
	Port     int32
}

Config is used to connect to a MysqlCluster

func NewConfigFromClusterKey

func NewConfigFromClusterKey(c client.Client, clusterKey client.ObjectKey) (*Config, error)

NewConfigFromClusterKey returns a new Config based on a MySQLCluster key

func (*Config) GetMysqlDSN

func (c *Config) GetMysqlDSN() string

GetMysqlDSN returns a data source name

type Query

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

Query contains a escaped query string with variables marked with a question mark (?) and a slice of positional arguments

func BuildAtomicQuery

func BuildAtomicQuery(queries ...Query) Query

BuildAtomicQuery concatenates the provided queries into a single query wrapped in a BEGIN COMMIT block

func ConcatenateQueries

func ConcatenateQueries(queries ...Query) Query

ConcatenateQueries concatenates the provided queries into a single query

func NewQuery

func NewQuery(q string, args ...interface{}) Query

NewQuery returns a new Query object

func (*Query) Args

func (q *Query) Args() []interface{}

Args is used in test

func (*Query) String

func (q *Query) String() string

String representation of the query

type Rows

type Rows interface {
	Err() error
	Next() bool
	Scan(dest ...interface{}) error
}

Rows interface is a subset of mysql.Rows

type SQLRunner

type SQLRunner interface {
	QueryExec(ctx context.Context, query Query) error
	QueryRow(ctx context.Context, query Query, dest ...interface{}) error
	QueryRows(ctx context.Context, query Query) (Rows, error)
}

SQLRunner interface is a subset of mysql.DB

func NewSQLRunner

func NewSQLRunner(cfg *Config, errs ...error) (SQLRunner, func(), error)

NewSQLRunner opens a connections using the given DSN

type SQLRunnerFactory

type SQLRunnerFactory func(cfg *Config, errs ...error) (SQLRunner, func(), error)

SQLRunnerFactory a function that generates a new SQLRunner

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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