mysql

package
v0.0.0-...-a020c25 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mysql provides methods to parse SQL and estimate MySQL data sizes.

Index

Constants

View Source
const (
	InnoDB = Engine("InnoDB")
	MyISAM = Engine("MyISAM")
)

List of supported engines.

View Source
const (
	Command          = "mysql"
	DefaultPerN      = 100
	DefaultPrecision = 2
)

Default values used to configure the estimator.

View Source
const (
	UnknownRowFormat    = RowFormat("")
	CompactRowFormat    = RowFormat("compact")
	CompressedRowFormat = RowFormat("compressed")
	DynamicRowFormat    = RowFormat("dynamic")
	RedundantRowFormat  = RowFormat("redundant")
	StaticRowFormat     = RowFormat("static")
)

List of known row formats

View Source
const DefaultCharset = "utf8mb4"

DefaultCharset is the default charset used as fail over in any charset is provided.

Variables

This section is empty.

Functions

func Charset

func Charset(sets ...string) string

Charset returns the first non empty string in the list or the default charset as failover.

Types

type Column

type Column struct {
	Name     string
	Charset  string
	DataSize uint64
	DataType DataType
	NotNull  bool
}

Column is a table's column.

func (Column) Kind

func (c Column) Kind() string

Kind implements the ds.Data interface.

func (Column) Size

func (c Column) Size() (min, max uint64)

Size implements the ds.Data interface.

func (Column) String

func (c Column) String() string

String implements the ds.Data interface.

type Config

type Config struct {
	Batch,
	Verbose bool
	Precision,
	PerN uint64
}

Config lists any customizable settings.

type Configurator

type Configurator func(*Estimator) error

Configurator is implemented by any method exposing cursor to adjust the estimator.

func SetBatchMode

func SetBatchMode(enabled bool) Configurator

SetBatchMode defines if the batch mode must be used to export the report in CSV format.

func SetPerN

func SetPerN(i uint64) Configurator

SetPerN defines the number of data to take account in the estimation.

func SetPrecision

func SetPrecision(i uint64) Configurator

SetPrecision defines the decimal precision used to print data size.

func SetVerbose

func SetVerbose(verbose bool) Configurator

SetVerbose defines the verbose mode to use to print the report.

type DataType

type DataType string

DataType represents a MySQL data type.

const (
	Bit        DataType = "bit"
	TinyInt    DataType = "tinyint"
	SmallInt   DataType = "smallint"
	MediumInt  DataType = "mediumint"
	Int        DataType = "int"
	Integer    DataType = "integer"
	BigInt     DataType = "bigint"
	Float      DataType = "float"
	Double     DataType = "double"
	Decimal    DataType = "decimal"
	Numeric    DataType = "numeric"
	Real       DataType = "real"
	Year       DataType = "year"
	Date       DataType = "date"
	Time       DataType = "time"
	Timestamp  DataType = "timestamp"
	DateTime   DataType = "datetime"
	Char       DataType = "char"
	Binary     DataType = "binary"
	VarChar    DataType = "varchar"
	VarBinary  DataType = "varbinary"
	TinyBlob   DataType = "tinyblob"
	TinyText   DataType = "tinytext"
	Blob       DataType = "blob"
	Text       DataType = "test"
	MediumBlob DataType = "mediumblob"
	MediumText DataType = "mediumtext"
	LongBlob   DataType = "longblob"
	LongText   DataType = "longtext"
	JSON       DataType = "json"
	Enum       DataType = "enum"
	Set        DataType = "set"
)

List of supported MySQL data types.

func ToDataType

func ToDataType(s string) DataType

ToDataType returns a MySQL DataType based on the given data name.

func (DataType) IsInt

func (d DataType) IsInt() bool

IsInt returns true if the data type is an integer.

func (DataType) IsString

func (d DataType) IsString() bool

IsString returns true if the data type is a string.

func (DataType) IsVar

func (d DataType) IsVar() bool

IsVar returns true if the data type is a variable one.

func (DataType) Kind

func (DataType) Kind() string

Kind implements the ds.Data interface.

func (DataType) Size

func (d DataType) Size(size uint64, charset string) (min, max uint64)

Size returns the required storage of the data type for this requested size in bytes and charset. It implements the ds.Data interface. todo To improve (decimal, numeric, etc.) See https://dev.mysql.com/doc/refman/8.0/en/storage-requirements.html

func (DataType) String

func (d DataType) String() string

String implements the ds.Data interface.

type Database

type Database struct {
	Name    string
	Charset string
	Tables  []Table
}

Database represents a database.

func (Database) Kind

func (d Database) Kind() string

Kind implements the ds.Data interface.

func (Database) Size

func (d Database) Size() (min, max uint64)

Size implements the ds.Data interface.

func (Database) String

func (d Database) String() string

String implements the ds.Data interface.

type Engine

type Engine string

Engine is an engine.

func ToEngine

func ToEngine(s string) Engine

ToEngine returns a MySQL engine based on the given engine name. By default the default MySQL engine is used if no one is provided.

func (Engine) Fields

func (e Engine) Fields(cols []Column) []ds.Data

Fields returns the columns with their sizes updated with engine and row format constrains.

func (Engine) Keys

func (e Engine) Keys(indexes []Index, primary int) []ds.Data

Keys returns the keys with their sizes updated with engine constrains.

func (Engine) RowFormat

func (e Engine) RowFormat(cols []Column, cur RowFormat) RowFormat

RowFormat defines the row format to use based on columns or the current value. sql: SELECT row_format FROM information_schema.tables WHERE table_schema="dbName" AND table_name="tbName";

func (Engine) RowSize

func (e Engine) RowSize(cols []Column, cur RowFormat) (min, max uint64)

RowSize returns the estimates row length.

func (Engine) String

func (e Engine) String() string

String implements the fmt.Stringer interface.

type Estimator

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

Estimator represents an MySQL data estimator.

func Estimate

func Estimate(opts ...Configurator) (*Estimator, error)

Estimate tries to instantiate a new estimator based on this configuration.

func (*Estimator) Run

func (e *Estimator) Run(r io.Reader, w io.Writer) error

Run runs the estimator.

type Index

type Index struct {
	Name    string
	Columns []Column
	Primary bool
}

Index is a table's key.

func (Index) Kind

func (i Index) Kind() string

Kind implements the ds.Data interface.

func (Index) Size

func (i Index) Size() (min, max uint64)

Size implements the ds.Data interface.

func (Index) String

func (i Index) String() string

String implements the ds.Data interface.

type RowFormat

type RowFormat string

RowFormat represents a row format.

func ToRowFormat

func ToRowFormat(s string) RowFormat

ToRowFormat returns a row format.

func (RowFormat) String

func (f RowFormat) String() string

String implements the fmt.Stringer interface.

type Storage

type Storage []Database

Storage represents a storage. It can contain many MySQL database.

func Parse

func Parse(r io.Reader) (Storage, error)

Parse parses the given SQL statements as MySQL queries. It tries to convert it as a Storage.

type Table

type Table struct {
	Name      string
	Engine    Engine
	Columns   []Column
	Indexes   []Index
	RowFormat RowFormat
}

Table represents a table.

func (*Table) Analyze

func (t *Table) Analyze() error

Analyze rechallenges any table properties to validate them, to define the primary key or the row format.

func (Table) Fields

func (t Table) Fields() []ds.Data

Fields returns columns properties.

func (Table) Keys

func (t Table) Keys() []ds.Data

Keys returns keys properties.

func (Table) Kind

func (t Table) Kind() string

Kind implements the ds.Data interface.

func (Table) Size

func (t Table) Size() (min, max uint64)

Size implements the ds.Data interface.

func (Table) String

func (t Table) String() string

String implements the ds.Data interface.

Jump to

Keyboard shortcuts

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