sqlutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanObjectName

func CleanObjectName(o string) string

func Float64

func Float64(s string) (float64, bool)

Float64 converts string to float64. If successful, it returns the float64 value and true, else it returns 0, false.

func FormatPercentile

func FormatPercentile(f float64) string

FormatPercentile formats a percentile into the form pNNN where NNN is the percentile up to 1 decimal point. For example, 0.99 returns "p99".

func INList

func INList(objs []string, quoteChar string) string

func MySQLVersion

func MySQLVersion(ctx context.Context, db *sql.DB) (int, int, int)

MySQLVersion returns the MySQL version as integers: major, minor, patch.

func MySQLVersionGTE

func MySQLVersionGTE(version string, db *sql.DB, ctx context.Context) (bool, error)

MySQLVersionGTE returns true if the current MySQL version is >= version. It returns false on any error.

func ObjectList

func ObjectList(csv string, quoteChar string) []string

func ParsePercentileStr

func ParsePercentileStr(percentileStr string) (float64, error)

ParsePercentileStr coverts a string of percentile in different form to the percentile as decimal. There are 3 kind of forms, like P99.9 has form 0.999, form 99.9 or form 999. All should be parsed as 0.999

func ReadOnly

func ReadOnly(err error) bool

ReadOnly returns true if the err is a MySQL read-only error caused by writing to a read-only instance.

func RowToMap

func RowToMap(ctx context.Context, db *sql.DB, query string) (map[string]string, error)

RowToMap converts a single row from query (or the last row) to a map of strings keyed on column name. All row values a converted to strings. This is used for one-row command outputs like SHOW SLAVE|REPLICA STATUS that have a mix of values and variaible columns (based on MySQL version) but the caller only needs specific cols/vals, so it uses this generic map rather than a specific struct.

func SanitizeTable

func SanitizeTable(table, db string) string

Types

type P

type P struct {
	Name  string
	Value float64
}

func PercentileMetrics

func PercentileMetrics(metrics []string) ([]P, error)

PercentileMetrics returns the list of percentile strings like "P95" in standard form (lowercase "p95") and decimal (0.95). It's used to process the metrics list for percentile collectors like query.response-time.

Jump to

Keyboard shortcuts

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