mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-07 15:45:59 +00:00
Add the sql concat function to query builder
This commit is contained in:
parent
249f9e6e2a
commit
3e28ce1254
@ -1,5 +1,7 @@
|
|||||||
package docspell.store.qb
|
package docspell.store.qb
|
||||||
|
|
||||||
|
import cats.data.NonEmptyList
|
||||||
|
|
||||||
sealed trait DBFunction {}
|
sealed trait DBFunction {}
|
||||||
|
|
||||||
object DBFunction {
|
object DBFunction {
|
||||||
@ -31,6 +33,8 @@ object DBFunction {
|
|||||||
|
|
||||||
case class Sum(expr: SelectExpr) extends DBFunction
|
case class Sum(expr: SelectExpr) extends DBFunction
|
||||||
|
|
||||||
|
case class Concat(exprs: NonEmptyList[SelectExpr]) extends DBFunction
|
||||||
|
|
||||||
sealed trait Operator
|
sealed trait Operator
|
||||||
object Operator {
|
object Operator {
|
||||||
case object Plus extends Operator
|
case object Plus extends Operator
|
||||||
|
@ -98,6 +98,9 @@ trait DSL extends DoobieMeta {
|
|||||||
def substring(expr: SelectExpr, start: Int, length: Int): DBFunction =
|
def substring(expr: SelectExpr, start: Int, length: Int): DBFunction =
|
||||||
DBFunction.Substring(expr, start, length)
|
DBFunction.Substring(expr, start, length)
|
||||||
|
|
||||||
|
def concat(expr: SelectExpr, exprs: SelectExpr*): DBFunction =
|
||||||
|
DBFunction.Concat(Nel.of(expr, exprs: _*))
|
||||||
|
|
||||||
def lit[A](value: A)(implicit P: Put[A]): SelectExpr.SelectLit[A] =
|
def lit[A](value: A)(implicit P: Put[A]): SelectExpr.SelectLit[A] =
|
||||||
SelectExpr.SelectLit(value, None)
|
SelectExpr.SelectLit(value, None)
|
||||||
|
|
||||||
|
@ -32,6 +32,10 @@ object DBFunctionBuilder extends CommonBuilder {
|
|||||||
case DBFunction.Substring(expr, start, len) =>
|
case DBFunction.Substring(expr, start, len) =>
|
||||||
sql"SUBSTRING(" ++ SelectExprBuilder.build(expr) ++ fr" FROM $start FOR $len)"
|
sql"SUBSTRING(" ++ SelectExprBuilder.build(expr) ++ fr" FROM $start FOR $len)"
|
||||||
|
|
||||||
|
case DBFunction.Concat(exprs) =>
|
||||||
|
val inner = exprs.map(SelectExprBuilder.build).toList.reduce(_ ++ comma ++ _)
|
||||||
|
sql"CONCAT(" ++ inner ++ sql")"
|
||||||
|
|
||||||
case DBFunction.Calc(op, left, right) =>
|
case DBFunction.Calc(op, left, right) =>
|
||||||
SelectExprBuilder.build(left) ++
|
SelectExprBuilder.build(left) ++
|
||||||
buildOperator(op) ++
|
buildOperator(op) ++
|
||||||
|
Loading…
x
Reference in New Issue
Block a user