Skip to content

Commit 1c56f16

Browse files
committed
Add GetWorkspaces query
This lets us retrieve all workspaces (for telemetry purposes).
1 parent 89e44da commit 1c56f16

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

coderd/database/databasefake/databasefake.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,22 @@ func (q *fakeQuerier) GetWorkspaceResourcesByJobID(_ context.Context, jobID uuid
10101010
return resources, nil
10111011
}
10121012

1013+
func (q *fakeQuerier) GetWorkspaces(_ context.Context, deleted bool) ([]database.Workspace, error) {
1014+
q.mutex.RLock()
1015+
defer q.mutex.RUnlock()
1016+
1017+
workspaces := make([]database.Workspace, 0)
1018+
for _, workspace := range q.workspaces {
1019+
if workspace.Deleted == deleted {
1020+
workspaces = append(workspaces, workspace)
1021+
}
1022+
}
1023+
if len(workspaces) == 0 {
1024+
return nil, sql.ErrNoRows
1025+
}
1026+
return workspaces, nil
1027+
}
1028+
10131029
func (q *fakeQuerier) GetProvisionerJobsByIDs(_ context.Context, ids []uuid.UUID) ([]database.ProvisionerJob, error) {
10141030
q.mutex.RLock()
10151031
defer q.mutex.RUnlock()

coderd/database/querier.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
-- name: GetWorkspaces :many
2+
SELECT * FROM workspaces WHERE deleted = $1;
3+
14
-- name: GetWorkspaceByID :one
25
SELECT
36
*

0 commit comments

Comments
 (0)