mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: add paginated API endpoint for groups (#27603)
backend-only changes from #27271; see that PR for summary of changes + implementation details
This commit is contained in:
@@ -91,6 +91,44 @@ WHERE
|
||||
LIMIT NULLIF(@limit_opt :: int, 0)
|
||||
;
|
||||
|
||||
-- name: GetGroupsByOrganizationIDPaginated :many
|
||||
SELECT
|
||||
sqlc.embed(groups),
|
||||
organizations.name AS organization_name,
|
||||
organizations.display_name AS organization_display_name,
|
||||
COUNT(*) OVER() AS count
|
||||
FROM
|
||||
groups
|
||||
INNER JOIN
|
||||
organizations ON groups.organization_id = organizations.id
|
||||
WHERE
|
||||
true
|
||||
AND groups.organization_id = @organization_id
|
||||
-- Keyset pagination cursor. When @after_id is set, return only groups
|
||||
-- ordered after it, matching the ORDER BY (LOWER(name), id) below. This
|
||||
-- lets callers page without duplicated or skipped rows even if groups are
|
||||
-- inserted or deleted between page requests.
|
||||
AND CASE
|
||||
WHEN @after_id :: uuid != '00000000-0000-0000-0000-000000000000' :: uuid THEN
|
||||
(LOWER(groups.name), groups.id) > (
|
||||
SELECT LOWER(name), id FROM groups WHERE id = @after_id
|
||||
)
|
||||
ELSE true
|
||||
END
|
||||
-- Filter by group name or display name (substring, case-insensitive).
|
||||
AND CASE WHEN @search :: text != '' THEN (
|
||||
groups.name ILIKE concat('%', @search, '%')
|
||||
OR groups.display_name ILIKE concat('%', @search, '%')
|
||||
)
|
||||
ELSE true
|
||||
END
|
||||
ORDER BY
|
||||
-- Deterministic and consistent ordering of all groups. This is to ensure consistent pagination.
|
||||
LOWER(groups.name) ASC, groups.id ASC OFFSET @offset_opt
|
||||
LIMIT
|
||||
-- A null limit means "no limit", so 0 means return all
|
||||
NULLIF(@limit_opt :: int, 0);
|
||||
|
||||
-- name: InsertGroup :one
|
||||
INSERT INTO groups (
|
||||
id,
|
||||
|
||||
Reference in New Issue
Block a user