mirror of
				https://github.com/TheAnachronism/docspell.git
				synced 2025-10-31 09:30:12 +00:00 
			
		
		
		
	Add the sql concat function to query builder
This commit is contained in:
		| @@ -1,5 +1,7 @@ | ||||
| package docspell.store.qb | ||||
|  | ||||
| import cats.data.NonEmptyList | ||||
|  | ||||
| sealed trait DBFunction {} | ||||
|  | ||||
| object DBFunction { | ||||
| @@ -31,6 +33,8 @@ object DBFunction { | ||||
|  | ||||
|   case class Sum(expr: SelectExpr) extends DBFunction | ||||
|  | ||||
|   case class Concat(exprs: NonEmptyList[SelectExpr]) extends DBFunction | ||||
|  | ||||
|   sealed trait Operator | ||||
|   object Operator { | ||||
|     case object Plus  extends Operator | ||||
|   | ||||
| @@ -98,6 +98,9 @@ trait DSL extends DoobieMeta { | ||||
|   def substring(expr: SelectExpr, start: Int, length: Int): DBFunction = | ||||
|     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] = | ||||
|     SelectExpr.SelectLit(value, None) | ||||
|  | ||||
|   | ||||
| @@ -32,6 +32,10 @@ object DBFunctionBuilder extends CommonBuilder { | ||||
|       case DBFunction.Substring(expr, start, 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) => | ||||
|         SelectExprBuilder.build(left) ++ | ||||
|           buildOperator(op) ++ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user