Merge pull request #884 from Vafilor/feat/filtering.updates

feat: updated workflow/workspace fields to allow some related field queries
This commit is contained in:
Rush Tehrani
2021-02-26 12:16:33 -08:00
committed by GitHub
2 changed files with 27 additions and 9 deletions

View File

@@ -2396,12 +2396,19 @@ func (c *Client) UpdateWorkflowExecutionMetrics(namespace, uid string, metrics M
// ListWorkflowExecutionsField loads all of the distinct field values for workflow executions // ListWorkflowExecutionsField loads all of the distinct field values for workflow executions
func (c *Client) ListWorkflowExecutionsField(namespace, field string) (value []string, err error) { 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) return nil, fmt.Errorf("unsupported field '%v'", field)
} }
columnName := fmt.Sprintf("we.%v", field)
sb := sb.Select(columnName). sb := sb.Select(columnName).
Distinct(). Distinct().
From("workflow_executions we"). From("workflow_executions we").

View File

@@ -985,18 +985,29 @@ func (c *Client) GetWorkspaceContainerLogs(namespace, uid, containerName string,
// ListWorkspacesField loads all of the distinct field values for workspaces // ListWorkspacesField loads all of the distinct field values for workspaces
func (c *Client) ListWorkspacesField(namespace, field string) (value []string, err error) { 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) return nil, fmt.Errorf("unsupported field '%v'", field)
} }
columnName := fmt.Sprintf("w.%v", field)
sb := sb.Select(columnName). sb := sb.Select(columnName).
Distinct(). Distinct().
From("workspaces w"). From("workspaces w").
Where(sq.Eq{ Join("workspace_templates wt ON w.workspace_template_id = wt.id").
"w.namespace": namespace, Where(sq.And{
}).OrderBy(columnName) sq.Eq{
"w.namespace": namespace,
}, sq.NotEq{
"w.phase": WorkspaceTerminated,
}}).OrderBy(columnName)
err = c.DB.Selectx(&value, sb) err = c.DB.Selectx(&value, sb)