[Feature] Add support for database views.

[Feature] Add support to manually set primary keys for destination structure fields.
This commit is contained in:
go-jet 2019-09-20 12:53:52 +02:00
parent 5b08a1d240
commit b88519bfd4
18 changed files with 462 additions and 128 deletions

View file

@ -31,7 +31,7 @@ func Generate(destDir string, dbConn DBConnection) error {
fmt.Println("Retrieving database information...")
// No schemas in MySQL
dbInfo, err := metadata.GetSchemaInfo(db, dbConn.DBName, &mySqlQuerySet{})
dbInfo, err := metadata.GetSchemaMetaData(db, dbConn.DBName, &mySqlQuerySet{})
if err != nil {
return err
@ -39,7 +39,7 @@ func Generate(destDir string, dbConn DBConnection) error {
genPath := path.Join(destDir, dbConn.DBName)
err = template.GenerateFiles(genPath, dbInfo.TableInfos, dbInfo.EnumInfos, mysql.Dialect)
err = template.GenerateFiles(genPath, dbInfo, mysql.Dialect)
if err != nil {
return err

View file

@ -13,7 +13,7 @@ func (m *mySqlQuerySet) ListOfTablesQuery() string {
return `
SELECT table_name
FROM INFORMATION_SCHEMA.tables
WHERE table_schema = ? and table_type = 'BASE TABLE';
WHERE table_schema = ? and table_type = ?;
`
}
@ -46,7 +46,7 @@ func (m *mySqlQuerySet) ListOfEnumsQuery() string {
SELECT (CASE c.DATA_TYPE WHEN 'enum' then CONCAT(c.TABLE_NAME, '_', c.COLUMN_NAME) ELSE '' END ), SUBSTRING(c.COLUMN_TYPE,5)
FROM information_schema.columns as c
INNER JOIN information_schema.tables as t on (t.table_schema = c.table_schema AND t.table_name = c.table_name)
WHERE c.table_schema = ? AND DATA_TYPE = 'enum' AND t.TABLE_TYPE = 'BASE TABLE';
WHERE c.table_schema = ? AND DATA_TYPE = 'enum';
`
}