dm

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: Apache-2.0 Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// 常规数据类型
	TypeChar            = "CHAR"             // 定长字符串,最大长度由数据库页面大小决定。
	TypeCharacter       = "CHARACTER"        // 定长字符串,最大长度由数据库页面大小决定。
	TypeVarchar         = "VARCHAR"          // 可变长字符串,最大长度由数据库页面大小决定。
	TypeNumeric         = "NUMERIC"          // 用于存储零、正负定点数。精度范围1至38
	TypeNumber          = "NUMBER"           // 跟NUMERIC相同
	TypeDecimal         = "DECIMAL"          // 跟NUMERIC相似
	TypeDec             = "DEC"              // 跟NUMERIC相似
	TypeInteger         = "INTEGER"          // 用于存储有符号整数,精度为10
	TypeInt             = "INT"              // 用于存储有符号整数,精度为10
	TypeBigint          = "BIGINT"           // 用于存储有符号整数,精度为19,标度为0
	TypeTinyint         = "TINYINT"          // 用于存储有符号整数,精度为3,标度为0。取值范围为:-128~+127
	TypeByte            = "BYTE"             // 与TINYINT相似,精度为3,标度为0
	TypeSmallint        = "SMALLINT"         // 用于存储有符号整数,精度为5,标度为0
	TypeBinary          = "BINARY"           // 指定定长二进制数据
	TypeVarbinary       = "VARBINARY"        // 指定变长二进制数据。用法类似BINARY数据类型
	TypeReal            = "REAL"             // 带二进制的浮点数
	TypeFloat           = "FLOAT"            // 二进制精度的浮点数,精度最大不超过53
	TypeDouble          = "DOUBLE"           // 同FLOAT相似,精度最大不超过53
	TypeDoublePrecision = "DOUBLE PRECISION" // 该类型指明双精度浮点数,其二进制精度为53,十进制精度为15

	//位串数据类型
	TypeBit = "BIT" // 用于存储整数数据1、0或null

	//日期时间数据类型
	TypeDate                       = "DATE"                           // 包括年、月、日信息,定义了‘-4712-01-01’和‘9999-12-31’之间任何一个有效的格里高利日期
	TypeTime                       = "TIME"                           // 包括时、分、秒信息
	TypeTimestamp                  = "TIMESTAMP"                      // 包括年、月、日、时、分、秒信息
	TypeDatetime                   = "DATETIME"                       // 包括年、月、日、时、分、秒信息
	TypeTimeWithTimeZone           = "TIME WITH TIME ZONE"            // 描述一个带时区的TIME值
	TypeTimestampWithTimeZone      = "TIMESTAMP WITH TIME ZONE"       // 描述一个带时区的TIMESTAMP值
	TypeTimestampWithLocalTimeZone = "TIMESTAMP WITH LOCAL TIME ZONE" // 描述一个本地时区的TIMESTAMP值

	//多媒体数据类型
	TypeText          = "TEXT"          // 变长字符串类型,其字符串的长度最大为2G-1,可用于存储长的文本串
	TypeLongvarchar   = "LONGVARCHAR"   // 变长字符串类型,其字符串的长度最大为2G-1,可用于存储长的文本串
	TypeImage         = "IMAGE"         // 可用于存储多媒体信息中的图像类型
	TypeLongvarbinary = "LONGVARBINARY" // 可用于存储多媒体信息中的图像类型
	TypeBlob          = "BLOB"          // 用于指明变长的字符串,长度最大为2G-1字节
	TypeClob          = "CLOB"          // 用于指明变长的字符串,长度最大为2G-1字节
	TypeBfile         = "BFILE"         // 用于指明存储在操作系统中的二进制文件

)
View Source
const (
	IndexTypeBTree    = "BTREE"
	IndexTypeHash     = "HASH"
	IndexTypeFullText = "FULLTEXT"
	IndexTypeSpatial  = "SPATIAL"

	IndexParserNGram = "ngram"
	IndexParserMeCab = "mecab"

	EngineInnoDB = "InnoDB"
	EngineMyISAM = "MyISAM"
	EngineMemory = "Memory"
	EngineCSV    = "CSV"
	EngineNDB    = "NDB" // NDBCLUSTER

)

Additional common constants in MySQL.

View Source
const DriverName = "dm"

DriverName holds the name used for registration.

Variables

View Source
var (

	// MarshalHCL marshals v into an Atlas HCL DDL document.
	MarshalHCL = schemahcl.MarshalerFunc(func(v any) ([]byte, error) {
		return MarshalSpec(v, hclState)
	})
	// EvalHCL implements the schemahcl.Evaluator interface.
	EvalHCL = schemahcl.EvalFunc(evalSpec)

	// EvalHCLBytes is a helper that evaluates an HCL document from a byte slice instead
	// of from an hclparse.Parser instance.
	EvalHCLBytes = specutil.HCLBytesFunc(EvalHCL)
)
View Source
var DefaultDiff schema.Differ = &sqlx.Diff{DiffDriver: &diff{conn: noConn}}

DefaultDiff provides basic diffing capabilities for MySQL dialects. Note, it is recommended to call Open, create a new Driver and use its Differ when a database connection is available.

View Source
var (

	// DefaultPlan provides basic planning capabilities for MySQL dialects.
	// Note, it is recommended to call Open, create a new Driver and use its
	// migrate.PlanApplier when a database connection is available.
	DefaultPlan migrate.PlanApplier = &planApply{conn: noConn}
)
View Source
var TypeRegistry = schemahcl.NewRegistry(
	schemahcl.WithFormatter(FormatType),
	schemahcl.WithParser(Parse),
	schemahcl.WithSpecs(

		schemahcl.NewTypeSpec(TypeBit, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeInt, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeDecimal, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		schemahcl.NewTypeSpec(TypeNumeric, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		schemahcl.NewTypeSpec(TypeFloat, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		schemahcl.NewTypeSpec(TypeDouble, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		schemahcl.NewTypeSpec(TypeReal, schemahcl.WithAttributes(unsignedTypeAttr(), schemahcl.PrecisionTypeAttr(), schemahcl.ScaleTypeAttr())),
		schemahcl.NewTypeSpec(TypeTimestamp, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr())),
		schemahcl.NewTypeSpec(TypeDate),
		schemahcl.NewTypeSpec(TypeTime, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr())),
		schemahcl.NewTypeSpec(TypeDatetime, schemahcl.WithAttributes(schemahcl.PrecisionTypeAttr())),
		schemahcl.NewTypeSpec(TypeVarchar, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(true))),
		schemahcl.NewTypeSpec(TypeChar, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeBinary, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeBlob, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeText, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeBigint),
		schemahcl.NewTypeSpec(TypeLongvarchar, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
		schemahcl.NewTypeSpec(TypeLongvarbinary, schemahcl.WithAttributes(schemahcl.SizeTypeAttr(false))),
	),
)

TypeRegistry contains the supported TypeSpecs for the mysql driver.

Functions

func FormatType

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 any, marshaler schemahcl.Marshaler) ([]byte, error)

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

func Open

Open opens a new MySQL driver.

func Parse added in v0.0.3

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

func ParseType

func ParseType(raw string, size, numericPrecision, numericScale int) (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.

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
	Size int
}

BitType represents the type bit.

type CreateOptions

type CreateOptions struct {
	schema.Attr
	V string
}

CreateOptions attribute for describing extra options used with CREATE TABLE.

type CreateStmt

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 (*Driver) CheckClean

func (d *Driver) CheckClean(ctx context.Context, revT *migrate.TableIdent) error

CheckClean implements migrate.CleanChecker.

func (*Driver) FormatType

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

FormatType converts schema type to its column form in the database.

func (*Driver) Lock

func (d *Driver) Lock(ctx context.Context, name string, timeout time.Duration) (schema.UnlockFunc, error)

Lock implements the schema.Locker interface.

func (*Driver) NormalizeRealm

func (d *Driver) NormalizeRealm(ctx context.Context, r *schema.Realm) (*schema.Realm, error)

NormalizeRealm returns the normal representation of the given database.

func (*Driver) NormalizeSchema

func (d *Driver) NormalizeSchema(ctx context.Context, s *schema.Schema) (*schema.Schema, error)

NormalizeSchema returns the normal representation of the given database.

func (*Driver) ParseType

func (*Driver) ParseType(s string) (schema.Type, error)

ParseType returns the schema.Type value represented by the given string.

func (*Driver) RealmRestoreFunc

func (d *Driver) RealmRestoreFunc(desired *schema.Realm) migrate.RestoreFunc

RealmRestoreFunc returns a function that restores the given realm to its desired state.

func (*Driver) ScanStmts

func (*Driver) ScanStmts(input string) ([]*migrate.Stmt, error)

ScanStmts implements migrate.StmtScanner.

func (*Driver) SchemaRestoreFunc

func (d *Driver) SchemaRestoreFunc(desired *schema.Schema) migrate.RestoreFunc

SchemaRestoreFunc returns a function that restores the given schema to its desired state.

func (*Driver) Snapshot

func (d *Driver) Snapshot(ctx context.Context) (migrate.RestoreFunc, error)

Snapshot implements migrate.Snapshoter.

func (*Driver) StmtBuilder

func (*Driver) StmtBuilder(opts migrate.PlanOptions) *sqlx.Builder

StmtBuilder is a helper method used to build statements with MySQL formatting.

func (*Driver) Version

func (d *Driver) Version() string

Version returns the version of the connected database.

type Enforced

type Enforced struct {
	schema.Attr
	V bool // V indicates if the CHECK is enforced or not.
}

Enforced attribute defines the ENFORCED flag for CHECK constraint.

type Engine

type Engine struct {
	schema.Attr
	V       string // InnoDB, MyISAM, etc.
	Default bool   // The default engine used by the server.
}

Engine attribute describes the storage engine used to create a table.

type IndexParser

type IndexParser struct {
	schema.Attr
	P string // Name of the parser plugin. e.g., ngram or mecab.
}

IndexParser defines the parser plugin used by a FULLTEXT index.

type IndexType

type IndexType struct {
	schema.Attr
	T string // BTREE, HASH, FULLTEXT, SPATIAL, 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