Skip to content

Commit

Permalink
Update models/db/context.go
Browse files Browse the repository at this point in the history
Co-authored-by: delvh <[email protected]>
  • Loading branch information
lunny and delvh authored May 21, 2022
1 parent b7476a9 commit be7d37c
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions models/db/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,18 @@ func EstimateCount(ctx context.Context, bean interface{}) (int64, error) {
e := GetEngine(ctx)
e.Context(ctx)

var rows int64
var err error
tablename := TableName(bean)
switch x.Dialect().URI().DBType {
case schemas.MYSQL:
var rows int64
_, err := e.Context(ctx).SQL("SELECT table_rows FROM information_schema.tables WHERE tables.table_name = ? AND tables.table_schema = ?;", tablename, x.Dialect().URI().DBName).Get(&rows)
return rows, err
_, err = e.Context(ctx).SQL("SELECT table_rows FROM information_schema.tables WHERE tables.table_name = ? AND tables.table_schema = ?;", tablename, x.Dialect().URI().DBName).Get(&rows)
case schemas.POSTGRES:
var rows int64
_, err := e.Context(ctx).SQL("SELECT reltuples AS estimate FROM pg_class WHERE relname = ?;", tablename).Get(&rows)
return rows, err
_, err = e.Context(ctx).SQL("SELECT reltuples AS estimate FROM pg_class WHERE relname = ?;", tablename).Get(&rows)
case schemas.MSSQL:
var rows int64
_, err := e.Context(ctx).SQL("sp_spaceused ?;", tablename).Get(&rows)
return rows, err
_, err = e.Context(ctx).SQL("sp_spaceused ?;", tablename).Get(&rows)
default:
return e.Context(ctx).Count(tablename)
}
return rows, err
}

0 comments on commit be7d37c

Please sign in to comment.