mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-04-05 10:59:33 +00:00
Extend query builder to compare results from subselects
This commit is contained in:
parent
7dcb61ef56
commit
988367a281
@ -19,6 +19,9 @@ object Condition {
|
|||||||
val P: Put[A]
|
val P: Put[A]
|
||||||
) extends Condition
|
) extends Condition
|
||||||
|
|
||||||
|
case class CompareSelect(sel: SelectExpr, op: Operator, subSelect: Select)
|
||||||
|
extends Condition
|
||||||
|
|
||||||
case class CompareCol[A](col1: Column[A], op: Operator, col2: Column[A])
|
case class CompareCol[A](col1: Column[A], op: Operator, col2: Column[A])
|
||||||
extends Condition
|
extends Condition
|
||||||
|
|
||||||
|
@ -215,6 +215,19 @@ trait DSL extends DoobieMeta {
|
|||||||
def in(subsel: Select): Condition =
|
def in(subsel: Select): Condition =
|
||||||
Condition.InSubSelect(col, subsel)
|
Condition.InSubSelect(col, subsel)
|
||||||
|
|
||||||
|
def >(subsel: Select): Condition =
|
||||||
|
Condition.CompareSelect(col.s, Operator.Gt, subsel)
|
||||||
|
def <(subsel: Select): Condition =
|
||||||
|
Condition.CompareSelect(col.s, Operator.Lt, subsel)
|
||||||
|
def >=(subsel: Select): Condition =
|
||||||
|
Condition.CompareSelect(col.s, Operator.Gte, subsel)
|
||||||
|
def <=(subsel: Select): Condition =
|
||||||
|
Condition.CompareSelect(col.s, Operator.Lte, subsel)
|
||||||
|
def ===(subsel: Select): Condition =
|
||||||
|
Condition.CompareSelect(col.s, Operator.Eq, subsel)
|
||||||
|
def !==(subsel: Select): Condition =
|
||||||
|
Condition.CompareSelect(col.s, Operator.Neq, subsel)
|
||||||
|
|
||||||
def notIn(subsel: Select): Condition =
|
def notIn(subsel: Select): Condition =
|
||||||
in(subsel).negate
|
in(subsel).negate
|
||||||
|
|
||||||
|
@ -100,6 +100,19 @@ object ConditionBuilder {
|
|||||||
}
|
}
|
||||||
c1Frag ++ operator(op) ++ c2Frag
|
c1Frag ++ operator(op) ++ c2Frag
|
||||||
|
|
||||||
|
case Condition.CompareSelect(col, op, subsel) =>
|
||||||
|
val opFrag = operator(op)
|
||||||
|
val colFrag = op match {
|
||||||
|
case Operator.LowerLike =>
|
||||||
|
lower(col)
|
||||||
|
case Operator.LowerEq =>
|
||||||
|
lower(col)
|
||||||
|
case _ =>
|
||||||
|
SelectExprBuilder.build(col)
|
||||||
|
}
|
||||||
|
val sub = SelectBuilder(subsel)
|
||||||
|
colFrag ++ opFrag ++ sql"(" ++ sub ++ sql")"
|
||||||
|
|
||||||
case Condition.InSubSelect(col, subsel) =>
|
case Condition.InSubSelect(col, subsel) =>
|
||||||
val sub = SelectBuilder(subsel)
|
val sub = SelectBuilder(subsel)
|
||||||
SelectExprBuilder.column(col) ++ sql" IN (" ++ sub ++ parenClose
|
SelectExprBuilder.column(col) ++ sql" IN (" ++ sub ++ parenClose
|
||||||
|
Loading…
x
Reference in New Issue
Block a user