Add qb.Like to query keys

This commit is contained in:
Maxim Karelov
2019-01-08 04:19:57 +04:00
committed by Michal Matczuk
parent 5007a41bf5
commit 6100d3b4c2
2 changed files with 17 additions and 0 deletions

View File

@@ -20,6 +20,7 @@ const (
in in
cnt cnt
cntKey cntKey
like
) )
// Cmp if a filtering comparator that is used in WHERE and IF clauses. // Cmp if a filtering comparator that is used in WHERE and IF clauses.
@@ -50,6 +51,8 @@ func (c Cmp) writeCql(cql *bytes.Buffer) (names []string) {
cql.WriteString(" CONTAINS ") cql.WriteString(" CONTAINS ")
case cntKey: case cntKey:
cql.WriteString(" CONTAINS KEY ") cql.WriteString(" CONTAINS KEY ")
case like:
cql.WriteString(" LIKE ")
} }
return c.value.writeCql(cql) return c.value.writeCql(cql)
} }
@@ -306,6 +309,15 @@ func ContainsLit(column, literal string) Cmp {
} }
} }
// Like produces column LIKE ?.
func Like(column string) Cmp {
return Cmp{
op: like,
column: column,
value: param(column),
}
}
type cmps []Cmp type cmps []Cmp
func (cs cmps) writeCql(cql *bytes.Buffer) (names []string) { func (cs cmps) writeCql(cql *bytes.Buffer) (names []string) {

View File

@@ -58,6 +58,11 @@ func TestCmp(t *testing.T) {
S: "cntKey CONTAINS KEY ?", S: "cntKey CONTAINS KEY ?",
N: []string{"cntKey"}, N: []string{"cntKey"},
}, },
{
C: Like("like"),
S: "like LIKE ?",
N: []string{"like"},
},
// Custom bind names // Custom bind names
{ {