You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

71 lines
1.3 KiB

package parser
import (
"git.diulo.com/mogfee/kit/mysql/ddl"
)
const timeImport = "time.Time"
type (
Table struct {
Name string
Db string
PrimaryKey Primary
UniqueIndex map[string][]*Field
Fields []*Field
}
Primary struct {
Field
AutoIncrement bool
}
Field struct {
NameOriginal string
Name string
DateType string
Comment string
SeqInIndex int
OrdinalPosition int
ContainsPQ bool
}
KeyType int
)
func parseNameOriginal(ts []*ddl.Table) (nameOriginals [][]string) {
var columns []string
for _, t := range ts {
columns = []string{}
for _, c := range t.Columns {
columns = append(columns, c.Name)
}
nameOriginals = append(nameOriginals, columns)
}
return nameOriginals
}
func Parse(filename, database string, strict bool) ([]*Table, error) {
list := make([]*Table, 0)
err := ddl.Parser(filename, func(table *ddl.Table) error {
list = append(list, &Table{
Name: table.Name,
Db: "",
PrimaryKey: Primary{
Field: Field{
NameOriginal: "",
Name: "",
DateType: "",
Comment: "",
SeqInIndex: 0,
OrdinalPosition: 0,
ContainsPQ: false,
},
AutoIncrement: false,
},
UniqueIndex: nil,
Fields: nil,
})
return nil
})
return list, err
}