Add <Cmp>TupleNamed for range-queries on tuples

This commit is contained in:
Drahflow
2022-02-11 21:08:00 +01:00
committed by Michal Jan Matczuk
parent b56c610884
commit 72221591cc

120
qb/cmp.go
View File

@@ -90,6 +90,18 @@ func EqNamed(column, name string) Cmp {
} }
} }
// EqTupleNamed produces column=(?,?,...) with count number of placeholders and custom name.
func EqTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: eq,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// EqLit produces column=literal and does not add a parameter to the query. // EqLit produces column=literal and does not add a parameter to the query.
func EqLit(column, literal string) Cmp { func EqLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -138,6 +150,18 @@ func NeNamed(column, name string) Cmp {
} }
} }
// NeTupleNamed produces column!=(?,?,...) with count number of placeholders and custom name.
func NeTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: ne,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// NeLit produces column!=literal and does not add a parameter to the query. // NeLit produces column!=literal and does not add a parameter to the query.
func NeLit(column, literal string) Cmp { func NeLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -186,6 +210,18 @@ func LtNamed(column, name string) Cmp {
} }
} }
// LtTupleNamed produces column<(?,?,...) with count placeholders and custom name.
func LtTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: lt,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// LtLit produces column<literal and does not add a parameter to the query. // LtLit produces column<literal and does not add a parameter to the query.
func LtLit(column, literal string) Cmp { func LtLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -234,6 +270,18 @@ func LtOrEqNamed(column, name string) Cmp {
} }
} }
// LtOrEqTupleNamed produces column<=(?,?,...) with count placeholders and custom name.
func LtOrEqTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: leq,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// LtOrEqLit produces column<=literal and does not add a parameter to the query. // LtOrEqLit produces column<=literal and does not add a parameter to the query.
func LtOrEqLit(column, literal string) Cmp { func LtOrEqLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -282,6 +330,18 @@ func GtNamed(column, name string) Cmp {
} }
} }
// GtTupleNamed produces column>(?,?,...) with count placeholders and custom name.
func GtTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: gt,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// GtLit produces column>literal and does not add a parameter to the query. // GtLit produces column>literal and does not add a parameter to the query.
func GtLit(column, literal string) Cmp { func GtLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -330,6 +390,18 @@ func GtOrEqNamed(column, name string) Cmp {
} }
} }
// GtOrEqTupleNamed produces column>=(?,?,...) with count placeholders and custom name.
func GtOrEqTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: geq,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// GtOrEqLit produces column>=literal and does not add a parameter to the query. // GtOrEqLit produces column>=literal and does not add a parameter to the query.
func GtOrEqLit(column, literal string) Cmp { func GtOrEqLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -378,6 +450,18 @@ func InNamed(column, name string) Cmp {
} }
} }
// InTupleNamed produces column IN ? with a custom parameter name.
func InTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: in,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// InLit produces column IN literal and does not add a parameter to the query. // InLit produces column IN literal and does not add a parameter to the query.
func InLit(column, literal string) Cmp { func InLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -447,6 +531,30 @@ func ContainsKeyNamed(column, name string) Cmp {
} }
} }
// ContainsTupleNamed produces column CONTAINS (?,?,...) with count placeholders and custom name.
func ContainsTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: cnt,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// ContainsKeyTupleNamed produces column CONTAINS KEY (?,?,...) with count placehplders and custom name.
func ContainsKeyTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: cntKey,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
// ContainsLit produces column CONTAINS literal and does not add a parameter to the query. // ContainsLit produces column CONTAINS literal and does not add a parameter to the query.
func ContainsLit(column, literal string) Cmp { func ContainsLit(column, literal string) Cmp {
return Cmp{ return Cmp{
@@ -477,6 +585,18 @@ func LikeTuple(column string, count int) Cmp {
} }
} }
// LikeTupleNamed produces column LIKE (?,?,...) with count placeholders and custom name.
func LikeTupleNamed(column string, count int, name string) Cmp {
return Cmp{
op: like,
column: column,
value: tupleParam{
param: param(name),
count: count,
},
}
}
type cmps []Cmp type cmps []Cmp
func (cs cmps) writeCql(cql *bytes.Buffer) (names []string) { func (cs cmps) writeCql(cql *bytes.Buffer) (names []string) {