Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5eea639

Browse files
committed
Unpack query correctly
1 parent 4d8e565 commit 5eea639

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

coderd/database/modelqueries.go

+5-33
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ func (q *sqlQuerier) GetAuthorizedWorkspaceCount(ctx context.Context, arg GetWor
220220
// authorizedFilter between the end of the where clause and those statements.
221221
filter := strings.Replace(getWorkspaceCount, "-- @authorize_filter", fmt.Sprintf(" AND %s", authorizedFilter.SQLString(rbac.NoACLConfig())), 1)
222222
// The name comment is for metric tracking
223-
query := fmt.Sprintf("-- name: GetAuthorizedWorkspaceCount :many\n%s", filter)
224-
rows, err := q.db.QueryContext(ctx, query,
223+
query := fmt.Sprintf("-- name: GetAuthorizedWorkspaceCount :one\n%s", filter)
224+
row := q.db.QueryRowContext(ctx, query,
225225
arg.Deleted,
226226
arg.Status,
227227
arg.OwnerID,
@@ -230,35 +230,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaceCount(ctx context.Context, arg GetWor
230230
pq.Array(arg.TemplateIds),
231231
arg.Name,
232232
)
233-
if err != nil {
234-
return 0, xerrors.Errorf("get authorized workspaces: %w", err)
235-
}
236-
defer rows.Close()
237-
var items []Workspace
238-
for rows.Next() {
239-
var i Workspace
240-
if err := rows.Scan(
241-
&i.ID,
242-
&i.CreatedAt,
243-
&i.UpdatedAt,
244-
&i.OwnerID,
245-
&i.OrganizationID,
246-
&i.TemplateID,
247-
&i.Deleted,
248-
&i.Name,
249-
&i.AutostartSchedule,
250-
&i.Ttl,
251-
&i.LastUsedAt,
252-
); err != nil {
253-
return 0, err
254-
}
255-
items = append(items, i)
256-
}
257-
if err := rows.Close(); err != nil {
258-
return 0, err
259-
}
260-
if err := rows.Err(); err != nil {
261-
return 0, err
262-
}
263-
return int64(len(items)), nil
233+
var count int64
234+
err := row.Scan(&count)
235+
return count, err
264236
}

0 commit comments

Comments
 (0)