1
0
mirror of https://github.com/astaxie/beego.git synced 2025-07-02 23:00:19 +00:00

orm Improve syncdb

This commit is contained in:
slene
2013-08-27 12:33:27 +08:00
parent 6686d9235c
commit 49bbca0ce3
8 changed files with 344 additions and 87 deletions

View File

@ -1116,3 +1116,61 @@ func (d *dbBase) TimeToDB(t *time.Time, tz *time.Location) {
func (d *dbBase) DbTypes() map[string]string {
return nil
}
func (d *dbBase) GetTables(db dbQuerier) (map[string]bool, error) {
tables := make(map[string]bool)
query := d.ins.ShowTablesQuery()
rows, err := db.Query(query)
if err != nil {
return tables, err
}
for rows.Next() {
var table string
err := rows.Scan(&table)
if err != nil {
return tables, err
}
if table != "" {
tables[table] = true
}
}
return tables, nil
}
func (d *dbBase) GetColumns(db dbQuerier, table string) (map[string][3]string, error) {
columns := make(map[string][3]string)
query := d.ins.ShowColumnsQuery(table)
rows, err := db.Query(query)
if err != nil {
return columns, err
}
for rows.Next() {
var (
name string
typ string
null string
)
err := rows.Scan(&name, &typ, &null)
if err != nil {
return columns, err
}
columns[name] = [3]string{name, typ, null}
}
return columns, nil
}
func (d *dbBase) ShowTablesQuery() string {
panic(ErrNotImplement)
}
func (d *dbBase) ShowColumnsQuery(table string) string {
panic(ErrNotImplement)
}
func (d *dbBase) IndexExists(dbQuerier, string, string) bool {
panic(ErrNotImplement)
}