db - amend SizeTable method
This commit is contained in:
parent
c3de6a3814
commit
d0cb5d8502
4
db/db.go
4
db/db.go
|
@ -176,7 +176,7 @@ type TableSize struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *Db) SizeTable(dbname string) []TableSize {
|
func (db *Db) SizeTable(dbname string) []TableSize {
|
||||||
rs := make([]TableSize, 1)
|
rs := make([]TableSize, 0)
|
||||||
db.onDbExec("information_schema", func(sqlDb *sql.DB) bool {
|
db.onDbExec("information_schema", func(sqlDb *sql.DB) bool {
|
||||||
query := "SELECT `TABLE_NAME` AS `table`, ROUND(((`DATA_LENGTH` + `INDEX_LENGTH`) / 1024 / 1024), 2) `size` FROM `TABLES` WHERE `table_schema` = ? AND (`DATA_LENGTH` + `INDEX_LENGTH`) > 0 ORDER BY (`DATA_LENGTH` + `INDEX_LENGTH`) DESC;"
|
query := "SELECT `TABLE_NAME` AS `table`, ROUND(((`DATA_LENGTH` + `INDEX_LENGTH`) / 1024 / 1024), 2) `size` FROM `TABLES` WHERE `table_schema` = ? AND (`DATA_LENGTH` + `INDEX_LENGTH`) > 0 ORDER BY (`DATA_LENGTH` + `INDEX_LENGTH`) DESC;"
|
||||||
rows, err := sqlDb.Query(query, dbname)
|
rows, err := sqlDb.Query(query, dbname)
|
||||||
|
@ -191,10 +191,8 @@ func (db *Db) SizeTable(dbname string) []TableSize {
|
||||||
fmt.Printf("cannot get table size of db %s : %v", dbname, err)
|
fmt.Printf("cannot get table size of db %s : %v", dbname, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(ts.Table) > 0 {
|
|
||||||
rs = append(rs, ts)
|
rs = append(rs, ts)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
return rs
|
return rs
|
||||||
|
|
Loading…
Reference in New Issue
Block a user