// tableSize returns a pretty string indicating the size in table. Row count // is always include, but the size on disk is only included if it's supported // by the database. // Note that 'name' is assumed to be SQL-safe. func tableSize(db *imdb.DB, name string) string { count := csql.Count(db, sf("SELECT COUNT(*) AS count FROM %s", name)) if db.Driver == "sqlite3" { return sf("%d rows", count) } var size string q := sf("SELECT pg_size_pretty(pg_relation_size('%s'))", name) csql.Scan(db.QueryRow(q), &size) return sf("%d rows (%s)", count, size) }
// databaseSize returns a pretty string indicating the size of the entire // database on disk. func databaseSize(db *imdb.DB, dsn string) string { if db.Driver == "sqlite3" { fi, err := os.Stat(dsn) csql.Panic(err) return prettyFileSize(fi.Size()) } var size string q := sf("SELECT pg_size_pretty(pg_database_size(current_database()))") csql.Scan(db.QueryRow(q), &size) return size }