Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // StructTagName is the key name of the tag string. StructTagName = "ddl" // IgnoreName is the string that myddlmaker ignores. IgnoreName = "-" )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { DB *DBConfig // OutFilePath is a file path for SQL generated by the DDL Maker. // If it is empty, "schema.sql" is used. OutFilePath string // OutGoFilePath is a file path for Go source code generated by the DDL Maker. // If it is empty, "schema_gen.go" is used. OutGoFilePath string // PackageName is a package name for Go source code generated by the DDL Maker. // If it is empty, "schema" is used. PackageName string // Tag is a build constraint tag for Go source code generated by the DDL Maker. // If it is empty, "myddlmaker" is used. Tag string // SkipValidationFKIndex disables index validation for foreign key constraints. SkipValidationFKIndex bool }
Config is a configuration of the DDL Maker.
type ForeignKey ¶
type ForeignKey struct {
// contains filtered or unexported fields
}
ForeignKey is a foreign key constraint. Implement the ForeignKeys method to define the foreign key constraints.
func (*User) ForeignKeys() []*myddlmaker.ForeignKey { return []*myddlmaker.ForeignKey{ // CONSTRAINT `name_of_constraint` // FOREIGN KEY (`column1`, `column2`) // REFERENCES `another_table` (`id1`, `id2`) myddlmaker.NewForeignKey( "name_of_constraint", []string{"column1", "column2"}, "another_table", []string{"id1", "id2"}, ), } }
func NewForeignKey ¶
func NewForeignKey(name string, columns []string, table string, references []string) *ForeignKey
NewForeignKey returns a new foreign key constraint.
func (*ForeignKey) OnDelete ¶
func (fk *ForeignKey) OnDelete(opt ForeignKeyOption) *ForeignKey
OnDelete returns a copy of fk with the referential action option opt specified by ON DELETE cause.
func (*ForeignKey) OnUpdate ¶
func (fk *ForeignKey) OnUpdate(opt ForeignKeyOption) *ForeignKey
OnUpdate returns a copy of fk with the referential action option opt specified by ON UPDATE cause.
type ForeignKeyOption ¶
type ForeignKeyOption string
ForeignKeyOption is an option of a referential action.
const ( // ForeignKeyOptionCascade deletes or updates the row from the parent table // and automatically delete or update the matching rows in the child table. ForeignKeyOptionCascade ForeignKeyOption = "CASCADE" // ForeignKeyOptionSetNull deletes or updates the row from the parent table // and set the foreign key column or columns in the child table to NULL. ForeignKeyOptionSetNull ForeignKeyOption = "SET NULL" // ForeignKeyOptionRestrict rejects the delete or update operation for the parent table. ForeignKeyOptionRestrict ForeignKeyOption = "RESTRICT" )
type FullTextIndex ¶
type FullTextIndex struct {
// contains filtered or unexported fields
}
FullTextIndex is a full text index. https://dev.mysql.com/doc/refman/8.0/en/innodb-fulltext-index.html Implement the `FullTextIndexes` method to define the full-text indexes.
func (*User) FullTextIndexes() []*myddlmaker.FullTextIndex { return []*myddlmaker.FullTextIndex{ // FULLTEXT INDEX `idx_name` (`name`) myddlmaker.NewFullTextIndex("idx_name", "name"), } }
func NewFullTextIndex ¶
func NewFullTextIndex(name string, column string) *FullTextIndex
NewFullTextIndex returns a new full text index.
func (*FullTextIndex) Comment ¶
func (idx *FullTextIndex) Comment(comment string) *FullTextIndex
Comment returns a copy of idx with the comment.
func (*FullTextIndex) Invisible ¶
func (idx *FullTextIndex) Invisible() *FullTextIndex
Invisible returns a copy of idx, but it is invisible from MySQL planner.
func (*FullTextIndex) WithParser ¶
func (idx *FullTextIndex) WithParser(parser string) *FullTextIndex
WithParser returns a copy of idx with the full-text plugin.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index is an index of a table. Implement the Indexes method to define the indexes.
func (*User) Indexes() []*myddlmaker.Index { return []*myddlmaker.Index{ // INDEX `idx_name` (`name`) myddlmaker.NewIndex("idx_name", "name"), } }
type JSON ¶ added in v0.0.5
type JSON[T any] [1]T
JSON[T] represents a MySQL JSON type tied to Go types. It is EXPERIMENTAL feature.
func (*JSON[T]) Scan ¶ added in v0.0.5
Scan implements database/sql.Scanner interface.
type Maker ¶
type Maker struct {
// contains filtered or unexported fields
}
func (*Maker) AddStructs ¶
func (*Maker) GenerateGoFile ¶
type PrimaryKey ¶
type PrimaryKey struct {
// contains filtered or unexported fields
}
func NewPrimaryKey ¶
func NewPrimaryKey(field ...string) *PrimaryKey
type SpatialIndex ¶
type SpatialIndex struct {
// contains filtered or unexported fields
}
SpatialIndex is a spatial index. Implement the SpatialIndexes method to define the spatial indexes.
func (*User) SpatialIndexes() []*myddlmaker.SpatialIndex { return []*myddlmaker.SpatialIndex{ // SPATIAL INDEX `idx_name` (`name`) myddlmaker.NewSpatialIndex("idx_name", "name"), } }
func NewSpatialIndex ¶
func NewSpatialIndex(name string, column string) *SpatialIndex
NewSpatialIndex returns a new spatial index.
func (*SpatialIndex) Comment ¶
func (idx *SpatialIndex) Comment(comment string) *SpatialIndex
Comment returns a copy of idx with the comment.
func (*SpatialIndex) Invisible ¶
func (idx *SpatialIndex) Invisible() *SpatialIndex
Invisible returns a copy of idx, but it is invisible from MySQL planner.
type Table ¶
type Table interface {
Table() string
}
Table is used for customizing the table name. It is an optional interface that may be implemented by a table.
// it generates CREATE TABLE `users` ... func (*User) Table() string { return "users" }
type TableComment ¶ added in v0.0.8
type TableComment interface {
TableComment() string
}
TableComment is used for customizing the table comment. It is an optional interface that may be implemented by a table.
// it generates CREATE TABLE `user` ( ... ) COMMENT='some comments' func (*User) TableComment() string { return "some comments" }
type UniqueIndex ¶
type UniqueIndex struct {
// contains filtered or unexported fields
}
UniqueIndex is a unique index of a table. Implement the UniqueIndexes method to define the unique indexes.
func (*User) UniqueIndexes() []*myddlmaker.Index { return []*myddlmaker.Index{ // UNIQUE INDEX `idx_name` (`name`) myddlmaker.NewUniqueIndex("idx_name", "name"), } }
func NewUniqueIndex ¶
func NewUniqueIndex(name string, col ...string) *UniqueIndex
NewUniqueIndex returns a new unique index.
func (*UniqueIndex) Comment ¶
func (idx *UniqueIndex) Comment(comment string) *UniqueIndex
Comment returns a copy of idx with the comment.
func (*UniqueIndex) Invisible ¶
func (idx *UniqueIndex) Invisible() *UniqueIndex
Invisible returns a copy of idx, but it is invisible from MySQL planner.