feat: Single query for all workspaces with optional filter (#1537)

* feat: Add single query for all workspaces using a filter
This commit is contained in:
Steven Masley
2022-05-18 10:09:07 -05:00
committed by GitHub
parent 894646cb7c
commit a3556b12da
16 changed files with 254 additions and 196 deletions

View File

@ -8,8 +8,27 @@ WHERE
LIMIT
1;
-- name: GetWorkspacesByOrganizationID :many
SELECT * FROM workspaces WHERE organization_id = $1 AND deleted = $2;
-- name: GetWorkspacesWithFilter :many
SELECT
*
FROM
workspaces
WHERE
-- Optionally include deleted workspaces
deleted = @deleted
-- Filter by organization_id
AND CASE
WHEN @organization_id :: uuid != '00000000-00000000-00000000-00000000' THEN
organization_id = @organization_id
ELSE true
END
-- Filter by owner_id
AND CASE
WHEN @owner_id :: uuid != '00000000-00000000-00000000-00000000' THEN
owner_id = @owner_id
ELSE true
END
;
-- name: GetWorkspacesByOrganizationIDs :many
SELECT * FROM workspaces WHERE organization_id = ANY(@ids :: uuid [ ]) AND deleted = @deleted;
@ -37,15 +56,6 @@ WHERE
template_id = $1
AND deleted = $2;
-- name: GetWorkspacesByOwnerID :many
SELECT
*
FROM
workspaces
WHERE
owner_id = $1
AND deleted = $2;
-- name: GetWorkspaceByOwnerIDAndName :one
SELECT
*