qb: tuple support

This commit is contained in:
Henrik Johansson
2019-05-13 11:30:19 +02:00
committed by Michal Matczuk
parent 31ae81aba6
commit 219bceab51
9 changed files with 238 additions and 0 deletions

108
qb/cmp.go
View File

@@ -66,6 +66,18 @@ func Eq(column string) Cmp {
}
}
// EqTuple produces column=(?,?,...) with count number of placeholders.
func EqTuple(column string, count int) Cmp {
return Cmp{
op: eq,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// EqNamed produces column=? with a custom parameter name.
func EqNamed(column, name string) Cmp {
return Cmp{
@@ -102,6 +114,18 @@ func Lt(column string) Cmp {
}
}
// LtTuple produces column<(?,?,...) with count placeholders.
func LtTuple(column string, count int) Cmp {
return Cmp{
op: lt,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// LtNamed produces column<? with a custom parameter name.
func LtNamed(column, name string) Cmp {
return Cmp{
@@ -138,6 +162,18 @@ func LtOrEq(column string) Cmp {
}
}
// LtOrEqTuple produces column<=(?,?,...) with count placeholders.
func LtOrEqTuple(column string, count int) Cmp {
return Cmp{
op: leq,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// LtOrEqNamed produces column<=? with a custom parameter name.
func LtOrEqNamed(column, name string) Cmp {
return Cmp{
@@ -174,6 +210,18 @@ func Gt(column string) Cmp {
}
}
// GtTuple produces column>(?,?,...) with count placeholders.
func GtTuple(column string, count int) Cmp {
return Cmp{
op: gt,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// GtNamed produces column>? with a custom parameter name.
func GtNamed(column, name string) Cmp {
return Cmp{
@@ -210,6 +258,18 @@ func GtOrEq(column string) Cmp {
}
}
// GtOrEqTuple produces column>=(?,?,...) with count placeholders.
func GtOrEqTuple(column string, count int) Cmp {
return Cmp{
op: geq,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// GtOrEqNamed produces column>=? with a custom parameter name.
func GtOrEqNamed(column, name string) Cmp {
return Cmp{
@@ -246,6 +306,18 @@ func In(column string) Cmp {
}
}
// InTuple produces column IN ?.
func InTuple(column string, count int) Cmp {
return Cmp{
op: in,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// InNamed produces column IN ? with a custom parameter name.
func InNamed(column, name string) Cmp {
return Cmp{
@@ -273,6 +345,18 @@ func Contains(column string) Cmp {
}
}
// ContainsTuple produces column CONTAINS (?,?,...) with count placeholders.
func ContainsTuple(column string, count int) Cmp {
return Cmp{
op: cnt,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// ContainsKey produces column CONTAINS KEY ?.
func ContainsKey(column string) Cmp {
return Cmp{
@@ -282,6 +366,18 @@ func ContainsKey(column string) Cmp {
}
}
// ContainsKeyTuple produces column CONTAINS KEY (?,?,...) with count placehplders.
func ContainsKeyTuple(column string, count int) Cmp {
return Cmp{
op: cntKey,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
// ContainsNamed produces column CONTAINS ? with a custom parameter name.
func ContainsNamed(column, name string) Cmp {
return Cmp{
@@ -318,6 +414,18 @@ func Like(column string) Cmp {
}
}
// LikeTuple produces column LIKE (?,?,...) with count placeholders.
func LikeTuple(column string, count int) Cmp {
return Cmp{
op: like,
column: column,
value: tupleParam{
param: param(column),
count: count,
},
}
}
type cmps []Cmp
func (cs cmps) writeCql(cql *bytes.Buffer) (names []string) {