Skip to content

Commit

Permalink
feat: gen multi database (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
qqxhb committed Nov 11, 2022
1 parent ca4edc1 commit ae06135
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions migrator.go
Expand Up @@ -183,7 +183,7 @@ func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) {
}
columnTypeSQL += "FROM information_schema.columns WHERE table_schema = ? AND table_name = ? ORDER BY ORDINAL_POSITION"

columns, rowErr := m.DB.Raw(columnTypeSQL, currentDatabase, table).Rows()
columns, rowErr := m.DB.Table(table).Raw(columnTypeSQL, currentDatabase, table).Rows()
if rowErr != nil {
return rowErr
}
Expand Down Expand Up @@ -271,7 +271,7 @@ func (m Migrator) GetIndexes(value interface{}) ([]gorm.Index, error) {

result := make([]*Index, 0)
schema, table := m.CurrentSchema(stmt, stmt.Table)
scanErr := m.DB.Raw(indexSql, schema, table).Scan(&result).Error
scanErr := m.DB.Table(table).Raw(indexSql, schema, table).Scan(&result).Error
if scanErr != nil {
return scanErr
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func (m Migrator) CurrentSchema(stmt *gorm.Statement, table string) (string, str
return tables[0], tables[1]
}
}

m.DB = m.DB.Table(table)
return m.CurrentDatabase(), table
}

Expand Down

0 comments on commit ae06135

Please sign in to comment.