Add peoples totalCount support

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2025-06-09 22:11:54 -07:00
parent d128e91c34
commit 9932212c39
7 changed files with 210 additions and 16 deletions

View File

@@ -293,6 +293,38 @@ DELETE FROM peoples WHERE %s AND id = @people_id
return err
}
func (p *Peoples) CountByOrganizationID(
ctx context.Context,
conn pg.Conn,
scope Scoper,
organizationID gid.GID,
) (int, error) {
q := `
SELECT
COUNT(id)
FROM
peoples
WHERE
%s
AND organization_id = @organization_id
`
q = fmt.Sprintf(q, scope.SQLFragment())
args := pgx.StrictNamedArgs{"organization_id": organizationID}
maps.Copy(args, scope.SQLArguments())
row := conn.QueryRow(ctx, q, args)
var count int
err := row.Scan(&count)
if err != nil {
return 0, fmt.Errorf("cannot count people: %w", err)
}
return count, nil
}
func (p *Peoples) LoadByOrganizationID(
ctx context.Context,
conn pg.Conn,