Skip to content

Commit e3bb788

Browse files
committed
exact matching is working
1 parent 45984ba commit e3bb788

File tree

5 files changed

+109
-42
lines changed

5 files changed

+109
-42
lines changed

coderd/database/modelqueries.go

+2
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
213213
// The name comment is for metric tracking
214214
query := fmt.Sprintf("-- name: GetAuthorizedWorkspaces :many\n%s", filtered)
215215
rows, err := q.db.QueryContext(ctx, query,
216+
pq.Array(arg.ParamNames),
217+
pq.Array(arg.ParamValues),
216218
arg.Deleted,
217219
arg.Status,
218220
arg.OwnerID,

coderd/database/querier.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

+73-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

+29-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ WHERE
7777
);
7878

7979
-- name: GetWorkspaces :many
80-
WITH filtered_workspaces AS (
80+
WITH
81+
-- build_params is used to filter by build parameters if present.
82+
-- It has to be a CTE because the set returning function 'unnest' cannot
83+
-- be used in a WHERE clause.
84+
build_params AS (
85+
SELECT
86+
LOWER(unnest(@param_names :: text[])) AS name,
87+
LOWER(unnest(@param_values :: text[])) AS value
88+
),
89+
filtered_workspaces AS (
8190
SELECT
8291
workspaces.*,
8392
COALESCE(template.name, 'unknown') as template_name,
@@ -200,6 +209,25 @@ WHERE
200209
)
201210
ELSE true
202211
END
212+
-- @param_value will match param name an value.
213+
-- requires 2 arrays, @param_names and @param_values to be passed in.
214+
-- Array index must match between the 2 arrays for name=value
215+
AND CASE WHEN array_length(@param_names :: text[], 1) > 0 THEN
216+
EXISTS (
217+
SELECT
218+
1
219+
FROM
220+
workspace_build_parameters
221+
INNER JOIN
222+
build_params
223+
ON
224+
LOWER(workspace_build_parameters.name) = build_params.name AND
225+
LOWER(workspace_build_parameters.value) = build_params.value AND
226+
workspace_build_parameters.workspace_build_id = latest_build.id
227+
)
228+
ELSE true
229+
END
230+
203231
-- Filter by owner_name
204232
AND CASE
205233
WHEN @owner_username :: text != '' THEN

coderd/searchquery/search.go

+2
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ func Workspaces(query string, page codersdk.Pagination, agentInactiveDisconnectT
148148
filter.HasParam = append(filter.HasParam, p.name)
149149
continue
150150
}
151+
filter.ParamNames = append(filter.ParamNames, p.name)
152+
filter.ParamValues = append(filter.ParamValues, *p.value)
151153
}
152154

153155
parser.ErrorExcessParams(values)

0 commit comments

Comments
 (0)