feat: workspace filter query supported in backend (#2232)

* feat: add support for template in workspace filter
* feat: Implement workspace search filter to support names
* Use new query param parser for pagination fields
* Remove excessive calls, use filters on a single query

Co-authored-by: Garrett <garrett@coder.com>
This commit is contained in:
Steven Masley
2022-06-14 08:46:33 -05:00
committed by GitHub
co-authored by Garrett
parent 5be52de593
commit dc1de58857
20 changed files with 1068 additions and 464 deletions
+22 -11
View File
@@ -8,13 +8,33 @@ WHERE
LIMIT
1;
-- name: GetTemplatesByIDs :many
-- name: GetTemplatesWithFilter :many
SELECT
*
FROM
templates
WHERE
id = ANY(@ids :: uuid [ ]);
-- Optionally include deleted templates
templates.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 exact name
AND CASE
WHEN @exact_name :: text != '' THEN
LOWER("name") = LOWER(@exact_name)
ELSE true
END
-- Filter by ids
AND CASE
WHEN array_length(@ids :: uuid[], 1) > 0 THEN
id = ANY(@ids)
ELSE true
END
;
-- name: GetTemplateByOrganizationAndName :one
SELECT
@@ -28,15 +48,6 @@ WHERE
LIMIT
1;
-- name: GetTemplatesByOrganization :many
SELECT
*
FROM
templates
WHERE
organization_id = $1
AND deleted = $2;
-- name: InsertTemplate :one
INSERT INTO
templates (