Add not equal comparator (!=)
The `qb.Cmp` lacks `not equal` methods related to the operator `!=` even though the documentation https://docs.scylladb.com/getting-started/dml/#select-statement mentions it. Closes: #114 Signed-off-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
This commit is contained in:
51
qb/cmp.go
51
qb/cmp.go
@@ -21,6 +21,7 @@ const (
|
||||
cnt
|
||||
cntKey
|
||||
like
|
||||
ne
|
||||
)
|
||||
|
||||
// Cmp if a filtering comparator that is used in WHERE and IF clauses.
|
||||
@@ -53,6 +54,8 @@ func (c Cmp) writeCql(cql *bytes.Buffer) (names []string) {
|
||||
cql.WriteString(" CONTAINS KEY ")
|
||||
case like:
|
||||
cql.WriteString(" LIKE ")
|
||||
case ne:
|
||||
cql.WriteString("!=")
|
||||
}
|
||||
return c.value.writeCql(cql)
|
||||
}
|
||||
@@ -105,6 +108,54 @@ func EqFunc(column string, fn *Func) Cmp {
|
||||
}
|
||||
}
|
||||
|
||||
// Ne produces column!=?.
|
||||
func Ne(column string) Cmp {
|
||||
return Cmp{
|
||||
op: ne,
|
||||
column: column,
|
||||
value: param(column),
|
||||
}
|
||||
}
|
||||
|
||||
// NeTuple produces column!=(?,?,...) with count number of placeholders.
|
||||
func NeTuple(column string, count int) Cmp {
|
||||
return Cmp{
|
||||
op: ne,
|
||||
column: column,
|
||||
value: tupleParam{
|
||||
param: param(column),
|
||||
count: count,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NeNamed produces column!=? with a custom parameter name.
|
||||
func NeNamed(column, name string) Cmp {
|
||||
return Cmp{
|
||||
op: ne,
|
||||
column: column,
|
||||
value: param(name),
|
||||
}
|
||||
}
|
||||
|
||||
// NeLit produces column!=literal and does not add a parameter to the query.
|
||||
func NeLit(column, literal string) Cmp {
|
||||
return Cmp{
|
||||
op: ne,
|
||||
column: column,
|
||||
value: lit(literal),
|
||||
}
|
||||
}
|
||||
|
||||
// NeFunc produces column!=someFunc(?...).
|
||||
func NeFunc(column string, fn *Func) Cmp {
|
||||
return Cmp{
|
||||
op: ne,
|
||||
column: column,
|
||||
value: fn,
|
||||
}
|
||||
}
|
||||
|
||||
// Lt produces column<?.
|
||||
func Lt(column string) Cmp {
|
||||
return Cmp{
|
||||
|
||||
Reference in New Issue
Block a user