Skip to content

Commit

Permalink
Merge pull request #1253 from nyaruka/contactql_prefixes_pt2
Browse files Browse the repository at this point in the history
Normalize contactql queries with type prefixes
  • Loading branch information
rowanseymour authored May 15, 2024
2 parents e38eec4 + 0138202 commit a4b4c95
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 73 deletions.
10 changes: 9 additions & 1 deletion contactql/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,22 @@ func (c *Condition) Simplify() QueryNode {
}

func (c *Condition) String() string {
property := c.propKey
value := c.value

// add prefix for fields and URNs
if c.propType == PropertyTypeField {
property = fmt.Sprintf(`fields.%s`, property)
} else if c.propType == PropertyTypeURN {
property = fmt.Sprintf(`urns.%s`, property)
}

if !isNumberRegex.MatchString(value) {
// if not a decimal then quote
value = strconv.Quote(value)
}

return fmt.Sprintf(`%s %s %s`, c.propKey, c.operator, value)
return fmt.Sprintf(`%s %s %s`, property, c.operator, value)
}

// BoolCombination is a AND or OR combination of multiple conditions
Expand Down
Loading

0 comments on commit a4b4c95

Please sign in to comment.