Documentation ¶
Index ¶
- func AddColumn(db *sqlx.DB, col Column) error
- func ChangeColumn(db *sqlx.DB, col Column) error
- func CheckAutoSet(defaultVal *string) bool
- func CheckAutoincrement(extra string) bool
- func CheckNull(null nullenum.Null) bool
- func CheckPk(key keyenum.Key) bool
- func CheckUnsigned(dbColType string) bool
- func CreateTable(db *sqlx.DB, t Table) error
- func NewFieldFromColumn(col Column) astutils.FieldMeta
- type Column
- type DbColumn
- type DbIndex
- type Index
- type IndexItem
- type IndexItems
- type Table
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckAutoSet ¶
func CheckAutoincrement ¶
func CheckUnsigned ¶
func NewFieldFromColumn ¶
Types ¶
type Column ¶
type Column struct { Table string Name string Type columnenum.ColumnType Default interface{} Pk bool Nullable bool Unsigned bool Autoincrement bool Extra extraenum.Extra Meta astutils.FieldMeta AutoSet bool Indexes []IndexItem }
func (*Column) AddColumnSql ¶
func (*Column) ChangeColumnSql ¶
type DbIndex ¶
type DbIndex struct { Table string `db:"Table"` // The name of the table Non_unique bool `db:"Non_unique"` // 1 if the index can contain duplicates, 0 if it cannot. Key_name string `db:"Key_name"` // The name of the index. The primary key index always has the name of PRIMARY. Seq_in_index int `db:"Seq_in_index"` // The column sequence number in the index. The first column sequence number starts from 1. Column_name string `db:"Column_name"` // The column name Collation string `db:"Collation"` // Collation represents how the column is sorted in the index. A means ascending, B means descending, or NULL means not sorted. }
https://www.mysqltutorial.org/mysql-index/mysql-show-indexes/
type IndexItems ¶
type IndexItems []IndexItem
func (IndexItems) Len ¶
func (it IndexItems) Len() int
func (IndexItems) Less ¶
func (it IndexItems) Less(i, j int) bool
func (IndexItems) Swap ¶
func (it IndexItems) Swap(i, j int)
type Table ¶
type Table struct { Name string Columns []Column Pk string Indexes []Index Meta astutils.StructMeta }
func NewTableFromStruct ¶
func NewTableFromStruct(structMeta astutils.StructMeta, prefix ...string) Table
Example ¶
var files []string var err error err = filepath.Walk(testDir, astutils.Visit(&files)) if err != nil { panic(err) } var sc astutils.StructCollector for _, file := range files { fset := token.NewFileSet() root, err := parser.ParseFile(fset, file, nil, parser.ParseComments) if err != nil { panic(err) } ast.Walk(&sc, root) } flattened := sc.FlatEmbed() for _, sm := range flattened { table := NewTableFromStruct(sm) fmt.Println(table) }
Output:
Click to show internal directories.
Click to hide internal directories.