blob: 0bca0de6425823ddace15ff9c03a49618aadab8d [file] [log] [blame]
// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package browserdevicedb
import (
"context"
"go.chromium.org/luci/common/errors"
"go.chromium.org/infra/fleetconsole/internal/database"
"go.chromium.org/infra/fleetconsole/internal/database/queryutils"
"go.chromium.org/infra/fleetconsole/internal/ent/entx"
"go.chromium.org/infra/fleetconsole/internal/ent/generated/browserdevice"
"go.chromium.org/infra/fleetconsole/internal/ent/generated/migrate"
)
// TotalCount counts the devices in the database.
func TotalCount(ctx context.Context, filter string, realms []string) (int, error) {
p, err := queryutils.ToEntPredicate(filter, migrate.BrowserDevicesTable)
if err != nil {
return 0, errors.Fmt("failed to parse filter: %w", err)
}
return database.GetEntClient(ctx).BrowserDevice.
Query().
Where(p).
Where(entx.RealmFilter(browserdevice.FieldRealm, realms)).
Count(ctx)
}