mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: implement filters for the organizations query (#14468)
Required for organization sync. Allows fetching a filtered set of orgs.
This commit is contained in:
@@ -4596,10 +4596,28 @@ SELECT
|
||||
id, name, description, created_at, updated_at, is_default, display_name, icon
|
||||
FROM
|
||||
organizations
|
||||
WHERE
|
||||
true
|
||||
-- Filter by ids
|
||||
AND CASE
|
||||
WHEN array_length($1 :: uuid[], 1) > 0 THEN
|
||||
id = ANY($1)
|
||||
ELSE true
|
||||
END
|
||||
AND CASE
|
||||
WHEN $2::text != '' THEN
|
||||
LOWER("name") = LOWER($2)
|
||||
ELSE true
|
||||
END
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetOrganizations(ctx context.Context) ([]Organization, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getOrganizations)
|
||||
type GetOrganizationsParams struct {
|
||||
IDs []uuid.UUID `db:"ids" json:"ids"`
|
||||
Name string `db:"name" json:"name"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetOrganizations(ctx context.Context, arg GetOrganizationsParams) ([]Organization, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getOrganizations, pq.Array(arg.IDs), arg.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user