-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from ergon/feature/dope-186-upgrade-clauses
Feature/dope 186 upgrade clauses
- Loading branch information
Showing
46 changed files
with
382 additions
and
491 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ch.ergon.dope | ||
|
||
import ch.ergon.dope.resolvable.clause.FromClause | ||
import ch.ergon.dope.resolvable.clause.SelectClause | ||
import ch.ergon.dope.resolvable.clause.SelectDistinctClause | ||
import ch.ergon.dope.resolvable.clause.SelectRawClause | ||
import ch.ergon.dope.resolvable.expression.AsteriskExpression | ||
import ch.ergon.dope.resolvable.expression.Expression | ||
import ch.ergon.dope.resolvable.expression.SingleExpression | ||
import ch.ergon.dope.resolvable.fromable.Fromable | ||
|
||
class QueryBuilder { | ||
fun select(expression: Expression, vararg expressions: Expression): SelectClause = SelectClause(expression, *expressions) | ||
|
||
fun selectAsterisk(): SelectClause = SelectClause(AsteriskExpression()) | ||
|
||
fun selectDistinct(expression: Expression, vararg expressions: Expression): SelectDistinctClause = | ||
SelectDistinctClause(expression, *expressions) | ||
|
||
fun selectRaw(expression: SingleExpression): SelectRawClause = SelectRawClause(expression) | ||
|
||
fun selectFrom(fromable: Fromable): FromClause = SelectClause(AsteriskExpression()).from(fromable) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/Clause.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
package ch.ergon.dope.resolvable.clause | ||
|
||
import ch.ergon.dope.resolvable.Resolvable | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.resetCounter | ||
|
||
interface Clause : Resolvable | ||
interface Clause : Resolvable { | ||
fun build(): String { | ||
resetCounter() | ||
return toQueryString() | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ClauseBuilder.kt
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package ch.ergon.dope.resolvable.clause | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.Field | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType | ||
import ch.ergon.dope.resolvable.fromable.AliasedSelectClause | ||
import ch.ergon.dope.resolvable.fromable.Bucket | ||
import ch.ergon.dope.resolvable.fromable.Fromable | ||
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 IOffsetClause : Clause | ||
|
||
interface ILimitClause : IOffsetClause { | ||
fun offset(numberExpression: TypeExpression<NumberType>): OffsetClause = OffsetClause(numberExpression, this) | ||
} | ||
|
||
interface IOrderByClause : ILimitClause { | ||
fun limit(numberExpression: TypeExpression<NumberType>): LimitClause = LimitClause(numberExpression, this) | ||
fun limit(number: Number): LimitClause = limit(number.toNumberType()) | ||
} | ||
|
||
interface IGroupByClause : IOrderByClause { | ||
fun orderBy(stringField: Field<StringType>): OrderByClause = OrderByClause(stringField, this) | ||
fun orderBy(stringField: Field<StringType>, orderByType: OrderByType): OrderByTypeClause = OrderByTypeClause(stringField, orderByType, this) | ||
} | ||
|
||
interface IWhereClause : IGroupByClause { | ||
fun groupBy(field: Field<out ValidType>, vararg fields: Field<out ValidType>): GroupByClause = | ||
GroupByClause(field, *fields, parentClause = this) | ||
} | ||
|
||
interface IFromClause : IWhereClause { | ||
fun where(whereExpression: TypeExpression<BooleanType>) = WhereClause(whereExpression, this) | ||
} | ||
|
||
interface IJoinClause : IFromClause { | ||
fun join(bucket: Bucket, onCondition: TypeExpression<BooleanType>) = StandardJoinClause(this, bucket, onCondition) | ||
fun join(bucket: Bucket, onKeys: Field<out ValidType>) = StandardJoinClause(this, bucket, onKeys) | ||
|
||
fun innerJoin(bucket: Bucket, onCondition: TypeExpression<BooleanType>) = InnerJoinClause(this, bucket, onCondition) | ||
fun innerJoin(bucket: Bucket, onKeys: Field<out ValidType>) = InnerJoinClause(this, bucket, onKeys) | ||
|
||
fun leftJoin(bucket: Bucket, onCondition: TypeExpression<BooleanType>) = LeftJoinClause(this, bucket, onCondition) | ||
fun leftJoin(bucket: Bucket, onKeys: Field<out ValidType>) = LeftJoinClause(this, bucket, onKeys) | ||
|
||
fun rightJoin(bucket: Bucket, onCondition: TypeExpression<BooleanType>) = RightJoinClause(this, bucket, onCondition) | ||
fun rightJoin(bucket: Bucket, onKeys: Field<out ValidType>) = RightJoinClause(this, bucket, onKeys) | ||
} | ||
|
||
interface ISelectClause : IFromClause { | ||
fun from(fromable: Fromable) = FromClause(fromable, this) | ||
|
||
fun alias(alias: String) = AliasedSelectClause(alias, this) | ||
} |
53 changes: 53 additions & 0 deletions
53
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/JoinClause.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ch.ergon.dope.resolvable.clause | ||
|
||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.Field | ||
import ch.ergon.dope.resolvable.fromable.Bucket | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
sealed class JoinClause : IJoinClause { | ||
private val queryString: String | ||
|
||
constructor(parentClause: IFromClause, joinType: String, bucket: Bucket, onCondition: TypeExpression<BooleanType>) { | ||
queryString = "${parentClause.toQueryString()} $joinType ${bucket.toQueryString()} ON ${onCondition.toQueryString()}" | ||
} | ||
|
||
constructor(parentClause: IFromClause, joinType: String, bucket: Bucket, key: Field<out ValidType>) { | ||
queryString = "${parentClause.toQueryString()} $joinType ${bucket.toQueryString()} ON KEYS ${key.toQueryString()}" | ||
} | ||
|
||
override fun toQueryString(): String = queryString | ||
} | ||
|
||
class StandardJoinClause : JoinClause { | ||
constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "JOIN", bucket, onKeys) | ||
} | ||
|
||
class LeftJoinClause : JoinClause { | ||
constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "LEFT JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "LEFT JOIN", bucket, onKeys) | ||
} | ||
|
||
class InnerJoinClause : JoinClause { | ||
constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "INNER JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "INNER JOIN", bucket, onKeys) | ||
} | ||
|
||
class RightJoinClause : JoinClause { | ||
constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "RIGHT JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "RIGHT JOIN", bucket, onKeys) | ||
} |
6 changes: 6 additions & 0 deletions
6
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ch.ergon.dope.resolvable.clause | ||
|
||
enum class OrderByType(val type: String) { | ||
ASC("ASC"), | ||
DESC("DESC"), | ||
} |
59 changes: 59 additions & 0 deletions
59
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package ch.ergon.dope.resolvable.clause | ||
|
||
import ch.ergon.dope.resolvable.expression.Expression | ||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.Field | ||
import ch.ergon.dope.resolvable.formatToQueryString | ||
import ch.ergon.dope.resolvable.fromable.Fromable | ||
import ch.ergon.dope.validtype.BooleanType | ||
import ch.ergon.dope.validtype.NumberType | ||
import ch.ergon.dope.validtype.StringType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
class OffsetClause(private val numberExpression: TypeExpression<NumberType>, private val parentClause: ILimitClause) : IOffsetClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "OFFSET", numberExpression) | ||
} | ||
|
||
class LimitClause(private val numberExpression: TypeExpression<NumberType>, private val parentClause: IOrderByClause) : ILimitClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "LIMIT", numberExpression) | ||
} | ||
|
||
open class OrderByClause(private val stringField: Field<StringType>, private val parentClause: IGroupByClause) : IOrderByClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "ORDER BY", stringField) | ||
} | ||
|
||
class OrderByTypeClause( | ||
stringField: Field<StringType>, | ||
private val orderByType: OrderByType, | ||
parentClause: IGroupByClause, | ||
) : OrderByClause(stringField, parentClause) { | ||
override fun toQueryString(): String = super.toQueryString() + " ${orderByType.type}" | ||
} | ||
|
||
class GroupByClause( | ||
private val field: Field<out ValidType>, | ||
private vararg val fields: Field<out ValidType>, | ||
private val parentClause: IWhereClause, | ||
) : IGroupByClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "GROUP BY", field, *fields) | ||
} | ||
|
||
class WhereClause(private val whereExpression: TypeExpression<BooleanType>, private val parentClause: IFromClause) : IWhereClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "WHERE", whereExpression) | ||
} | ||
|
||
class FromClause(private val fromable: Fromable, private val parentClause: ISelectClause) : IJoinClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "FROM", fromable) | ||
} | ||
|
||
class SelectRawClause(private val expression: Expression) : ISelectClause { | ||
override fun toQueryString(): String = formatToQueryString("SELECT RAW", expression) | ||
} | ||
|
||
class SelectDistinctClause(private val expression: Expression, private vararg val expressions: Expression) : ISelectClause { | ||
override fun toQueryString(): String = formatToQueryString("SELECT DISTINCT", expression, *expressions) | ||
} | ||
|
||
class SelectClause(private val expression: Expression, private vararg val expressions: Expression) : ISelectClause { | ||
override fun toQueryString(): String = formatToQueryString("SELECT", expression, *expressions) | ||
} |
11 changes: 0 additions & 11 deletions
11
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/FromClause.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/GroupByClause.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/LetClause.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/LimitClause.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/OffsetClause.kt
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/OrderByClause.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/SelectClause.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.