feat: update admin
This commit is contained in:
@@ -310,3 +310,24 @@ func (m *usersModel) HasBought(ctx context.Context, userID, postID int64) (bool,
|
||||
|
||||
return userPost.ID > 0, nil
|
||||
}
|
||||
|
||||
// Count
|
||||
func (m *usersModel) Count(ctx context.Context, cond BoolExpression) (int64, error) {
|
||||
tbl := table.Users
|
||||
stmt := tbl.
|
||||
SELECT(COUNT(tbl.ID).AS("cnt")).
|
||||
WHERE(cond)
|
||||
|
||||
m.log.Infof("sql: %s", stmt.DebugSql())
|
||||
|
||||
var cnt struct {
|
||||
Cnt int64
|
||||
}
|
||||
|
||||
if err := stmt.QueryContext(ctx, db, &cnt); err != nil {
|
||||
m.log.Errorf("error counting users: %v", err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return cnt.Cnt, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user