From 6100d3b4c2302c06ac10a3e04b0fcc1e02a4cf5b Mon Sep 17 00:00:00 2001 From: Maxim Karelov Date: Tue, 8 Jan 2019 04:19:57 +0400 Subject: [PATCH] Add qb.Like to query keys --- qb/cmp.go | 12 ++++++++++++ qb/cmp_test.go | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/qb/cmp.go b/qb/cmp.go index 53bfec8..4a83a8c 100644 --- a/qb/cmp.go +++ b/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) { diff --git a/qb/cmp_test.go b/qb/cmp_test.go index 32e3a2c..b6eb653 100644 --- a/qb/cmp_test.go +++ b/qb/cmp_test.go @@ -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 {