mysql

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: Apache-2.0 Imports: 16 Imported by: 30

Documentation

Index

Constants

View Source
const (
	TypeBit       = "bit"       // MYSQL_TYPE_BIT
	TypeInt       = "int"       // MYSQL_TYPE_LONG
	TypeTinyInt   = "tinyint"   // MYSQL_TYPE_TINY
	TypeSmallInt  = "smallint"  // MYSQL_TYPE_SHORT
	TypeMediumInt = "mediumint" // MYSQL_TYPE_INT24
	TypeBigInt    = "bigint"    // MYSQL_TYPE_LONGLONG

	TypeDecimal = "decimal" // MYSQL_TYPE_DECIMAL
	TypeNumeric = "numeric" // MYSQL_TYPE_DECIMAL (numeric_type rule in sql_yacc.yy)
	TypeFloat   = "float"   // MYSQL_TYPE_FLOAT
	TypeDouble  = "double"  // MYSQL_TYPE_DOUBLE
	TypeReal    = "real"    // MYSQL_TYPE_FLOAT or MYSQL_TYPE_DOUBLE (real_type in sql_yacc.yy)

	TypeTimestamp = "timestamp" // MYSQL_TYPE_TIMESTAMP
	TypeDate      = "date"      // MYSQL_TYPE_DATE
	TypeTime      = "time"      // MYSQL_TYPE_TIME
	TypeDateTime  = "datetime"  // MYSQL_TYPE_DATETIME
	TypeYear      = "year"      // MYSQL_TYPE_YEAR

	TypeVarchar    = "varchar"    // MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VARCHAR
	TypeChar       = "char"       // MYSQL_TYPE_STRING
	TypeVarBinary  = "varbinary"  // MYSQL_TYPE_VAR_STRING + NULL CHARACTER_SET.
	TypeBinary     = "binary"     // MYSQL_TYPE_STRING + NULL CHARACTER_SET.
	TypeBlob       = "blob"       // MYSQL_TYPE_BLOB
	TypeTinyBlob   = "tinyblob"   // MYSQL_TYPE_TINYBLOB
	TypeMediumBlob = "mediumblob" // MYSQL_TYPE_MEDIUM_BLOB
	TypeLongBlob   = "longblob"   // MYSQL_TYPE_LONG_BLOB
	TypeText       = "text"       // MYSQL_TYPE_BLOB + CHARACTER_SET utf8mb4
	TypeTinyText   = "tinytext"   // MYSQL_TYPE_TINYBLOB + CHARACTER_SET utf8mb4
	TypeMediumText = "mediumtext" // MYSQL_TYPE_MEDIUM_BLOB + CHARACTER_SET utf8mb4
	TypeLongText   = "longtext"   // MYSQL_TYPE_LONG_BLOB with + CHARACTER_SET utf8mb4

	TypeEnum = "enum" // MYSQL_TYPE_ENUM
	TypeSet  = "set"  // MYSQL_TYPE_SET
	TypeJSON = "json" // MYSQL_TYPE_JSON

	TypeGeometry           = "geometry"           // MYSQL_TYPE_GEOMETRY
	TypePoint              = "point"              // Geometry_type::kPoint
	TypeMultiPoint         = "multipoint"         // Geometry_type::kMultipoint
	TypeLineString         = "linestring"         // Geometry_type::kLinestring
	TypeMultiLineString    = "multilinestring"    // Geometry_type::kMultilinestring
	TypePolygon            = "polygon"            // Geometry_type::kPolygon
	TypeMultiPolygon       = "multipolygon"       // Geometry_type::kMultipolygon
	TypeGeoCollection      = "geomcollection"     // Geometry_type::kGeometrycollection
	TypeGeometryCollection = "geometrycollection" // Geometry_type::kGeometrycollection
)

MySQL standard column types as defined in its codebase. Name and order is organized differently than MySQL.

https://github.com/mysql/mysql-server/blob/8.0/include/field_types.h https://github.com/mysql/mysql-server/blob/8.0/sql/dd/types/column.h https://github.com/mysql/mysql-server/blob/8.0/sql/sql_show.cc https://github.com/mysql/mysql-server/blob/8.0/sql/gis/geometries.cc

Variables

View Source
var (

	// UnmarshalHCL unmarshals an Atlas HCL DDL document into v.
	UnmarshalHCL = schemaspec.UnmarshalerFunc(func(bytes []byte, i interface{}) error {
		return UnmarshalSpec(bytes, hclState, i)
	})
	// MarshalHCL marshals v into an Atlas HCL DDL document.
	MarshalHCL = schemaspec.MarshalerFunc(func(v interface{}) ([]byte, error) {
		return MarshalSpec(v, hclState)
	})
)
View Source
var TypeRegistry = specutil.NewRegistry(
	specutil.WithFormatter(FormatType),
	specutil.WithParser(ParseType),
	specutil.WithSpecs(
		&schemaspec.TypeSpec{
			Name: TypeEnum,
			T:    TypeEnum,
			Attributes: []*schemaspec.TypeAttr{
				{Name: "values", Kind: reflect.Slice, Required: true},
			},
			RType: reflect.TypeOf(schema.EnumType{}),
		},
		&schemaspec.TypeSpec{
			Name: TypeSet,
			T:    TypeSet,
			Attributes: []*schemaspec.TypeAttr{
				{Name: "values", Kind: reflect.Slice, Required: true},
			},
			RType: reflect.TypeOf(SetType{}),
		},
		specutil.TypeSpec(TypeBit, specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeTinyInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeSmallInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeMediumInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeBigInt, unsignedTypeAttr(), specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeDecimal, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
		specutil.TypeSpec(TypeNumeric, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
		specutil.TypeSpec(TypeFloat, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
		specutil.TypeSpec(TypeDouble, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
		specutil.TypeSpec(TypeReal, &schemaspec.TypeAttr{Name: "precision", Kind: reflect.Int, Required: false}, &schemaspec.TypeAttr{Name: "scale", Kind: reflect.Int, Required: false}),
		specutil.TypeSpec(TypeTimestamp),
		specutil.TypeSpec(TypeDate),
		specutil.TypeSpec(TypeTime),
		specutil.TypeSpec(TypeDateTime),
		specutil.TypeSpec(TypeYear),
		specutil.TypeSpec(TypeVarchar, specutil.SizeTypeAttr(true)),
		specutil.TypeSpec(TypeChar, specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeVarBinary, specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeBinary, specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeBlob, specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeTinyBlob),
		specutil.TypeSpec(TypeMediumBlob),
		specutil.TypeSpec(TypeLongBlob),
		specutil.TypeSpec(TypeJSON),
		specutil.TypeSpec(TypeText, specutil.SizeTypeAttr(false)),
		specutil.TypeSpec(TypeTinyText),
		specutil.TypeSpec(TypeMediumText),
		specutil.TypeSpec(TypeLongText),
		specutil.TypeSpec(TypeGeometry),
		specutil.TypeSpec(TypePoint),
		specutil.TypeSpec(TypeMultiPoint),
		specutil.TypeSpec(TypeLineString),
		specutil.TypeSpec(TypeMultiLineString),
		specutil.TypeSpec(TypePolygon),
		specutil.TypeSpec(TypeMultiPolygon),
		specutil.TypeSpec(TypeGeometryCollection),
	),
)

TypeRegistry contains the supported TypeSpecs for the mysql driver.

Functions

func Build

func Build(phrase string) *sqlx.Builder

Build instantiates a new builder and writes the given phrase to it.

func FormatType added in v0.2.0

func FormatType(t schema.Type) (string, error)

FormatType converts schema type to its column form in the database. An error is returned if the type cannot be recognized.

func MarshalSpec

func MarshalSpec(v interface{}, marshaler schemaspec.Marshaler) ([]byte, error)

MarshalSpec marshals v into an Atlas DDL document using a schemaspec.Marshaler.

func ParseType added in v0.2.0

func ParseType(raw string) (schema.Type, error)

ParseType returns the schema.Type value represented by the given raw type. The raw value is expected to follow the format in MySQL information schema.

func UnmarshalSpec

func UnmarshalSpec(data []byte, unmarshaler schemaspec.Unmarshaler, v interface{}) error

UnmarshalSpec unmarshals an Atlas DDL document using an unmarshaler into v.

Types

type AutoIncrement

type AutoIncrement struct {
	schema.Attr
	V int64
}

AutoIncrement attribute for columns with "AUTO_INCREMENT" as a default. V represent an optional start value for the counter.

type BitType

type BitType struct {
	schema.Type
	T string
}

BitType represents a bit type.

type CreateOptions added in v0.2.0

type CreateOptions struct {
	schema.Attr
	V string
}

CreateOptions attribute for describing extra options used with CREATE TABLE.

type CreateStmt added in v0.3.0

type CreateStmt struct {
	schema.Attr
	S string
}

CreateStmt describes the SQL statement used to create a table.

type DisplayWidth

type DisplayWidth struct {
	schema.Attr
	N int
}

The DisplayWidth represents a display width of an integer type.

type Driver

type Driver struct {
	schema.Differ
	schema.Inspector
	migrate.PlanApplier
	// contains filtered or unexported fields
}

Driver represents a MySQL driver for introspecting database schemas, generating diff between schema elements and apply migrations changes.

func Open

func Open(db schema.ExecQuerier) (*Driver, error)

Open opens a new MySQL driver.

type Enforced added in v0.2.0

type Enforced struct {
	schema.Attr
}

Enforced attribute defines the ENFORCED flag for CHECK constraint. Similar to AUTO_INCREMENT, checks with this attributes are enforced.

type IndexType

type IndexType struct {
	schema.Attr
	T string // BTREE, FULLTEXT, HASH, RTREE
}

IndexType represents an index type.

type OnUpdate

type OnUpdate struct {
	schema.Attr
	A string
}

OnUpdate attribute for columns with "ON UPDATE CURRENT_TIMESTAMP" as a default.

type SetType

type SetType struct {
	schema.Type
	Values []string
}

SetType represents a set type.

type SubPart

type SubPart struct {
	schema.Attr
	Len int
}

SubPart attribute defines an option index prefix length for columns.

type ZeroFill

type ZeroFill struct {
	schema.Attr
	A string
}

The ZeroFill represents the ZEROFILL attribute which is deprecated for MySQL version >= 8.0.17.

Jump to

Keyboard shortcuts

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