Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated workflow/workspace fields to allow some related field queries #884

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/workflow_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -2390,12 +2390,19 @@ func (c *Client) UpdateWorkflowExecutionMetrics(namespace, uid string, metrics M

// ListWorkflowExecutionsField loads all of the distinct field values for workflow executions
func (c *Client) ListWorkflowExecutionsField(namespace, field string) (value []string, err error) {
if field != "name" {
columnName := ""

switch field {
case "name":
columnName = "we.name"
break
case "templateName":
columnName = "wt.name"
break
default:
return nil, fmt.Errorf("unsupported field '%v'", field)
}

columnName := fmt.Sprintf("we.%v", field)

sb := sb.Select(columnName).
Distinct().
From("workflow_executions we").
Expand Down
23 changes: 17 additions & 6 deletions pkg/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,18 +985,29 @@ func (c *Client) GetWorkspaceContainerLogs(namespace, uid, containerName string,

// ListWorkspacesField loads all of the distinct field values for workspaces
func (c *Client) ListWorkspacesField(namespace, field string) (value []string, err error) {
if field != "name" {
columnName := ""

switch field {
case "name":
columnName = "w.name"
break
case "templateName":
columnName = "wt.name"
break
default:
return nil, fmt.Errorf("unsupported field '%v'", field)
}

columnName := fmt.Sprintf("w.%v", field)

sb := sb.Select(columnName).
Distinct().
From("workspaces w").
Where(sq.Eq{
"w.namespace": namespace,
}).OrderBy(columnName)
Join("workspace_templates wt ON w.workspace_template_id = wt.id").
Where(sq.And{
sq.Eq{
"w.namespace": namespace,
}, sq.NotEq{
"w.phase": WorkspaceTerminated,
}}).OrderBy(columnName)

err = c.DB.Selectx(&value, sb)

Expand Down