Skip to content

Commit

Permalink
Merge branch 'refs/heads/main' into feature/dope-239-object-funcitons
Browse files Browse the repository at this point in the history
  • Loading branch information
jansigi committed Nov 21, 2024
2 parents c5b7e69 + c710fcd commit 4a74f87
Show file tree
Hide file tree
Showing 24 changed files with 1,180 additions and 90 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/reviewer.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fun formatPathToQueryString(name: String, path: String) =
if (path.isBlank()) {
"`$name`"
} else {
"`$path`.`$name`"
"${path.split(".").joinToString(".") { "`$it`" }}.`$name`"
}

fun formatStringListToQueryStringWithBrackets(dopeQueries: List<String>, separator: String = ", ", prefix: String = "(", postfix: String = ")") =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import ch.ergon.dope.resolvable.clause.model.GroupByClause
import ch.ergon.dope.resolvable.clause.model.InnerJoinClause
import ch.ergon.dope.resolvable.clause.model.LeftJoinClause
import ch.ergon.dope.resolvable.clause.model.OrderByType
import ch.ergon.dope.resolvable.clause.model.OrderExpression
import ch.ergon.dope.resolvable.clause.model.RightJoinClause
import ch.ergon.dope.resolvable.clause.model.SelectLimitClause
import ch.ergon.dope.resolvable.clause.model.SelectOffsetClause
import ch.ergon.dope.resolvable.clause.model.SelectOrderByClause
import ch.ergon.dope.resolvable.clause.model.SelectOrderByTypeClause
import ch.ergon.dope.resolvable.clause.model.SelectWhereClause
import ch.ergon.dope.resolvable.clause.model.StandardJoinClause
import ch.ergon.dope.resolvable.clause.model.UnnestClause
Expand All @@ -27,7 +27,6 @@ import ch.ergon.dope.resolvable.fromable.Joinable
import ch.ergon.dope.validtype.ArrayType
import ch.ergon.dope.validtype.BooleanType
import ch.ergon.dope.validtype.NumberType
import ch.ergon.dope.validtype.StringType
import ch.ergon.dope.validtype.ValidType

interface ISelectOffsetClause<T : ValidType> : Clause {
Expand All @@ -46,9 +45,10 @@ interface ISelectOrderByClause<T : ValidType> : ISelectLimitClause<T> {
}

interface ISelectGroupByClause<T : ValidType> : ISelectOrderByClause<T> {
fun orderBy(stringField: Field<StringType>) = SelectOrderByClause(stringField, this)
fun orderBy(stringField: Field<StringType>, orderByType: OrderByType) =
SelectOrderByTypeClause(stringField, orderByType, this)
fun orderBy(expression: TypeExpression<out ValidType>, orderByType: OrderByType? = null) = SelectOrderByClause(
OrderExpression(expression, orderByType),
parentClause = this,
)
}

interface ISelectWhereClause<T : ValidType> : ISelectGroupByClause<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,58 @@ package ch.ergon.dope.resolvable.clause.model

import ch.ergon.dope.DopeQuery
import ch.ergon.dope.DopeQueryManager
import ch.ergon.dope.resolvable.Resolvable
import ch.ergon.dope.resolvable.clause.ISelectGroupByClause
import ch.ergon.dope.resolvable.clause.ISelectOrderByClause
import ch.ergon.dope.resolvable.expression.unaliased.type.Field
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.formatToQueryStringWithSymbol
import ch.ergon.dope.validtype.StringType
import ch.ergon.dope.validtype.ValidType

enum class OrderByType(val type: String) {
enum class OrderByType(val queryString: String) {
ASC("ASC"),
DESC("DESC"),
}

private const val ORDER_BY = "ORDER BY"

open class SelectOrderByClause<T : ValidType>(private val stringField: Field<StringType>, private val parentClause: ISelectGroupByClause<T>) :
ISelectOrderByClause<T> {

class SelectOrderByClause<T : ValidType>(
private val orderExpression: OrderExpression,
private vararg val additionalOrderExpressions: OrderExpression,
private val parentClause: ISelectGroupByClause<T>,
) : ISelectOrderByClause<T> {
override fun toDopeQuery(manager: DopeQueryManager): DopeQuery {
val parentDopeQuery = parentClause.toDopeQuery(manager)
val stringDopeQuery = stringField.toDopeQuery(manager)
val orderExpressionDopeQuery = orderExpression.toDopeQuery(manager)
val additionalOrderExpressions = additionalOrderExpressions.map { it.toDopeQuery(manager) }
return DopeQuery(
queryString = formatToQueryStringWithSymbol(parentDopeQuery.queryString, ORDER_BY, stringDopeQuery.queryString),
parameters = parentDopeQuery.parameters.merge(stringDopeQuery.parameters),
queryString = formatToQueryStringWithSymbol(
parentDopeQuery.queryString,
ORDER_BY,
orderExpressionDopeQuery.queryString,
*additionalOrderExpressions.map { it.queryString }.toTypedArray(),
),
parameters = parentDopeQuery.parameters.merge(
orderExpressionDopeQuery.parameters,
*additionalOrderExpressions.map { it.parameters }.toTypedArray(),
),
)
}
}

class SelectOrderByTypeClause<T : ValidType>(
private val stringField: Field<StringType>,
private val orderByType: OrderByType,
private val parentClause: ISelectGroupByClause<T>,
) : SelectOrderByClause<T>(stringField, parentClause) {
fun thenOrderBy(typeExpression: TypeExpression<out ValidType>, orderByType: OrderByType? = null) =
SelectOrderByClause(
this.orderExpression,
*additionalOrderExpressions,
OrderExpression(typeExpression, orderByType),
parentClause = this.parentClause,
)
}

class OrderExpression(private val expression: TypeExpression<out ValidType>, private val orderByType: OrderByType? = null) : Resolvable {
override fun toDopeQuery(manager: DopeQueryManager): DopeQuery {
val parentDopeQuery = parentClause.toDopeQuery(manager)
val stringDopeQuery = stringField.toDopeQuery(manager)
val typeDopeQuery = expression.toDopeQuery(manager)
return DopeQuery(
queryString = formatToQueryStringWithSymbol(
parentDopeQuery.queryString,
ORDER_BY,
stringDopeQuery.queryString + " $orderByType",
),
parameters = parentDopeQuery.parameters.merge(stringDopeQuery.parameters),
queryString = listOfNotNull(typeDopeQuery.queryString, orderByType?.queryString).joinToString(separator = " "),
parameters = typeDopeQuery.parameters,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfuncti
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType
import ch.ergon.dope.validtype.StringType

class MBPosition1Expression(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) :
FunctionExpression<StringType>("MB_POSITION1", inStr, searchStr)
FunctionExpression<NumberType>("MB_POSITION1", inStr, searchStr)

fun mbPosition1(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) =
MBPosition1Expression(inStr, searchStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfuncti
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType
import ch.ergon.dope.validtype.StringType

class MBPositionExpression(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) :
FunctionExpression<StringType>("MB_POSITION", inStr, searchStr)
FunctionExpression<NumberType>("MB_POSITION", inStr, searchStr)

fun mbPosition(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) =
MBPositionExpression(inStr, searchStr)
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfuncti
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType
import ch.ergon.dope.validtype.StringType

class Position1Expression(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) :
FunctionExpression<StringType>("POSITION1", inStr, searchStr)
FunctionExpression<NumberType>("POSITION1", inStr, searchStr)

fun position1(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) =
Position1Expression(inStr, searchStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfuncti
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType
import ch.ergon.dope.validtype.StringType

class PositionExpression(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) :
FunctionExpression<StringType>("POSITION", inStr, searchStr)
FunctionExpression<NumberType>("POSITION", inStr, searchStr)

fun position(inStr: TypeExpression<StringType>, searchStr: TypeExpression<StringType>) =
PositionExpression(inStr, searchStr)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfunction

import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.NumberType
import ch.ergon.dope.validtype.StringType

class ReplaceExpression(
inStr: TypeExpression<StringType>,
searchStr: TypeExpression<StringType>,
replace: TypeExpression<StringType>,
numberOfInstances: TypeExpression<NumberType>? = null,
) : FunctionExpression<StringType>("REPLACE", inStr, searchStr, replace, numberOfInstances)

fun replace(
inStr: TypeExpression<StringType>,
searchStr: TypeExpression<StringType>,
replace: TypeExpression<StringType>,
numberOfInstances: TypeExpression<NumberType>? = null,
) = ReplaceExpression(inStr, searchStr, replace, numberOfInstances)

fun replace(
inStr: TypeExpression<StringType>,
searchStr: TypeExpression<StringType>,
replace: TypeExpression<StringType>,
numberOfInstances: Int,
) = replace(inStr, searchStr, replace, numberOfInstances.toDopeType())

fun replace(
inStr: TypeExpression<StringType>,
searchStr: TypeExpression<StringType>,
replace: String,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr, searchStr, replace.toDopeType(), numberOfInstances)

fun replace(
inStr: TypeExpression<StringType>,
searchStr: TypeExpression<StringType>,
replace: String,
numberOfInstances: Int,
) = replace(inStr, searchStr, replace.toDopeType(), numberOfInstances.toDopeType())

fun replace(
inStr: TypeExpression<StringType>,
searchStr: String,
replace: TypeExpression<StringType>,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr, searchStr.toDopeType(), replace, numberOfInstances)

fun replace(
inStr: TypeExpression<StringType>,
searchStr: String,
replace: TypeExpression<StringType>,
numberOfInstances: Int,
) = replace(inStr, searchStr.toDopeType(), replace, numberOfInstances.toDopeType())

fun replace(
inStr: TypeExpression<StringType>,
searchStr: String,
replace: String,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr, searchStr.toDopeType(), replace.toDopeType(), numberOfInstances)

fun replace(
inStr: TypeExpression<StringType>,
searchStr: String,
replace: String,
numberOfInstances: Int,
) = replace(inStr, searchStr.toDopeType(), replace.toDopeType(), numberOfInstances.toDopeType())

fun replace(
inStr: String,
searchStr: TypeExpression<StringType>,
replace: TypeExpression<StringType>,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr.toDopeType(), searchStr, replace, numberOfInstances)

fun replace(
inStr: String,
searchStr: TypeExpression<StringType>,
replace: TypeExpression<StringType>,
numberOfInstances: Int,
) = replace(inStr.toDopeType(), searchStr, replace, numberOfInstances.toDopeType())

fun replace(
inStr: String,
searchStr: TypeExpression<StringType>,
replace: String,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr.toDopeType(), searchStr, replace.toDopeType(), numberOfInstances)

fun replace(
inStr: String,
searchStr: TypeExpression<StringType>,
replace: String,
numberOfInstances: Int,
) = replace(inStr.toDopeType(), searchStr, replace.toDopeType(), numberOfInstances.toDopeType())

fun replace(
inStr: String,
searchStr: String,
replace: TypeExpression<StringType>,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr.toDopeType(), searchStr.toDopeType(), replace, numberOfInstances)

fun replace(
inStr: String,
searchStr: String,
replace: TypeExpression<StringType>,
numberOfInstances: Int,
) = replace(inStr.toDopeType(), searchStr.toDopeType(), replace, numberOfInstances.toDopeType())

fun replace(
inStr: String,
searchStr: String,
replace: String,
numberOfInstances: TypeExpression<NumberType>? = null,
) = replace(inStr.toDopeType(), searchStr.toDopeType(), replace.toDopeType(), numberOfInstances)

fun replace(
inStr: String,
searchStr: String,
replace: String,
numberOfInstances: Int,
) = replace(inStr.toDopeType(), searchStr.toDopeType(), replace.toDopeType(), numberOfInstances.toDopeType())
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfuncti
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.ArrayType
import ch.ergon.dope.validtype.StringType

class SplitExpression(inStr: TypeExpression<StringType>, inSubstring: TypeExpression<StringType>? = null) :
FunctionExpression<StringType>("SPLIT", inStr, inSubstring)
FunctionExpression<ArrayType<StringType>>("SPLIT", inStr, inSubstring)

fun split(inStr: TypeExpression<StringType>, inSubstring: TypeExpression<StringType>? = null) =
SplitExpression(inStr, inSubstring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfuncti
import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.FunctionExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.toDopeType
import ch.ergon.dope.validtype.ArrayType
import ch.ergon.dope.validtype.StringType

class SuffixesExpression(inStr: TypeExpression<StringType>) :
FunctionExpression<StringType>("SUFFIXES", inStr)
FunctionExpression<ArrayType<StringType>>("SUFFIXES", inStr)

fun suffixes(inStr: TypeExpression<StringType>) = SuffixesExpression(inStr)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ch.ergon.dope.resolvable.expression.TypeExpression
import ch.ergon.dope.resolvable.expression.unaliased.type.function.stringfunction.factory.CustomTokenOptions
import ch.ergon.dope.resolvable.formatStringListToQueryStringWithBrackets
import ch.ergon.dope.resolvable.operator.FunctionOperator
import ch.ergon.dope.validtype.ArrayType
import ch.ergon.dope.validtype.StringType

// Argument {"case":"lower"} is optional. Valid values are lower or upper.
Expand All @@ -14,7 +15,7 @@ import ch.ergon.dope.validtype.StringType
class TokensExpression(
private val inStr: List<String>,
private val opt: CustomTokenOptions = CustomTokenOptions(),
) : TypeExpression<StringType>, FunctionOperator {
) : TypeExpression<ArrayType<StringType>>, FunctionOperator {
override fun toDopeQuery(manager: DopeQueryManager): DopeQuery {
val optDopeQuery = opt.toDopeQuery()
return DopeQuery(
Expand Down
Loading

0 comments on commit 4a74f87

Please sign in to comment.