Add qb.Like to query keys
This commit is contained in:
committed by
Michal Matczuk
parent
5007a41bf5
commit
6100d3b4c2
12
qb/cmp.go
12
qb/cmp.go
@@ -20,6 +20,7 @@ const (
|
||||
in
|
||||
cnt
|
||||
cntKey
|
||||
like
|
||||
)
|
||||
|
||||
// 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 ")
|
||||
case cntKey:
|
||||
cql.WriteString(" CONTAINS KEY ")
|
||||
case like:
|
||||
cql.WriteString(" LIKE ")
|
||||
}
|
||||
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
|
||||
|
||||
func (cs cmps) writeCql(cql *bytes.Buffer) (names []string) {
|
||||
|
||||
@@ -58,6 +58,11 @@ func TestCmp(t *testing.T) {
|
||||
S: "cntKey CONTAINS KEY ?",
|
||||
N: []string{"cntKey"},
|
||||
},
|
||||
{
|
||||
C: Like("like"),
|
||||
S: "like LIKE ?",
|
||||
N: []string{"like"},
|
||||
},
|
||||
|
||||
// Custom bind names
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user