Skip to content

Commit

Permalink
allow = in filters to target column
Browse files Browse the repository at this point in the history
  • Loading branch information
isaaguilar committed Oct 20, 2023
1 parent dcc44d9 commit 6106a6f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion pkg/api/get_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"time"

ptylib "github.com/creack/pty"
Expand Down Expand Up @@ -132,7 +133,39 @@ func (h APIHandler) workflows(c *gin.Context) {

if matchAny != "" {
m := fmt.Sprintf("%%%s%%", matchAny)
query.Where("(tfo_resources.name LIKE ? or tfo_resources.namespace LIKE ? or clusters.name LIKE ?)", m, m, m)
name := m
namespace := m
clusterName := m

if strings.Contains(matchAny, "=") {
name = "%"
namespace = "%"
clusterName = "%"
for _, matchAnyOfColumn := range strings.Split(matchAny, " ") {
if !strings.Contains(matchAnyOfColumn, "=") {
continue
}
columnQuery := strings.Split(matchAnyOfColumn, "=")
key := columnQuery[0]
value := columnQuery[1]
if key == "name" {
query.Where("tfo_resources.name LIKE ?", fmt.Sprintf("%%%s%%", value))
}
if key == "namespace" {
query.Where("tfo_resources.namespace LIKE ?", fmt.Sprintf("%%%s%%", value))
}
if strings.HasPrefix(key, "cluster") {
query.Where("clusters.name LIKE ?", fmt.Sprintf("%%%s%%", value))
}
}
} else {
query.Where("(tfo_resources.name LIKE ? or tfo_resources.namespace LIKE ? or clusters.name LIKE ?)",
name,
namespace,
clusterName,
)
}

}

query.Scan(&result)
Expand Down

0 comments on commit 6106a6f

Please sign in to comment.