-
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 #13 from ergon/feature/dope-209-delete-clause
DOPE-209: added DeleteClause
- Loading branch information
Showing
19 changed files
with
396 additions
and
148 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.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,32 @@ | ||
package ch.ergon.dope.resolvable.clause | ||
|
||
import ch.ergon.dope.resolvable.clause.model.DeleteLimitClause | ||
import ch.ergon.dope.resolvable.clause.model.DeleteOffsetClause | ||
import ch.ergon.dope.resolvable.clause.model.DeleteWhereClause | ||
import ch.ergon.dope.resolvable.clause.model.ReturningClause | ||
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.validtype.BooleanType | ||
import ch.ergon.dope.validtype.NumberType | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
interface IDeleteReturningClause : Clause | ||
|
||
interface IDeleteOffsetClass : IDeleteReturningClause { | ||
fun returning(field: Field<out ValidType>, vararg fields: Field<out ValidType>) = ReturningClause(field, *fields, parentClause = this) | ||
} | ||
|
||
interface IDeleteLimitClass : IDeleteOffsetClass { | ||
fun offset(numberExpression: TypeExpression<NumberType>) = DeleteOffsetClause(numberExpression, this) | ||
fun offset(number: Number): DeleteOffsetClause = offset(number.toNumberType()) | ||
} | ||
|
||
interface IDeleteWhereClause : IDeleteLimitClass { | ||
fun limit(numberExpression: TypeExpression<NumberType>) = DeleteLimitClause(numberExpression, this) | ||
fun limit(number: Number): DeleteLimitClause = limit(number.toNumberType()) | ||
} | ||
|
||
interface IDeleteClause : IDeleteWhereClause { | ||
fun where(booleanExpression: TypeExpression<BooleanType>) = DeleteWhereClause(booleanExpression, this) | ||
} |
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
53 changes: 0 additions & 53 deletions
53
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/JoinClause.kt
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByType.kt
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/DeleteClause.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,8 @@ | ||
package ch.ergon.dope.resolvable.clause.model | ||
|
||
import ch.ergon.dope.resolvable.clause.IDeleteClause | ||
import ch.ergon.dope.resolvable.fromable.Bucket | ||
|
||
class DeleteClause(private val bucket: Bucket) : IDeleteClause { | ||
override fun toQueryString(): String = "DELETE FROM ${bucket.toQueryString()}" | ||
} |
10 changes: 10 additions & 0 deletions
10
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/FromClause.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,10 @@ | ||
package ch.ergon.dope.resolvable.clause.model | ||
|
||
import ch.ergon.dope.resolvable.clause.ISelectClause | ||
import ch.ergon.dope.resolvable.clause.ISelectJoinClause | ||
import ch.ergon.dope.resolvable.formatToQueryString | ||
import ch.ergon.dope.resolvable.fromable.Fromable | ||
|
||
class FromClause(private val fromable: Fromable, private val parentClause: ISelectClause) : ISelectJoinClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "FROM", fromable) | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/GroupByClause.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,15 @@ | ||
package ch.ergon.dope.resolvable.clause.model | ||
|
||
import ch.ergon.dope.resolvable.clause.ISelectGroupByClause | ||
import ch.ergon.dope.resolvable.clause.ISelectWhereClause | ||
import ch.ergon.dope.resolvable.expression.unaliased.type.Field | ||
import ch.ergon.dope.resolvable.formatToQueryString | ||
import ch.ergon.dope.validtype.ValidType | ||
|
||
class GroupByClause( | ||
private val field: Field<out ValidType>, | ||
private vararg val fields: Field<out ValidType>, | ||
private val parentClause: ISelectWhereClause, | ||
) : ISelectGroupByClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, "GROUP BY", field, *fields) | ||
} |
55 changes: 55 additions & 0 deletions
55
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/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,55 @@ | ||
package ch.ergon.dope.resolvable.clause.model | ||
|
||
import ch.ergon.dope.resolvable.clause.ISelectFromClause | ||
import ch.ergon.dope.resolvable.clause.ISelectJoinClause | ||
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 SelectJoinClause : ISelectJoinClause { | ||
private val queryString: String | ||
|
||
constructor(parentClause: ISelectFromClause, joinType: String, bucket: Bucket, onCondition: TypeExpression<BooleanType>) { | ||
queryString = "${parentClause.toQueryString()} $joinType ${bucket.toQueryString()} ON ${onCondition.toQueryString()}" | ||
} | ||
|
||
constructor(parentClause: ISelectFromClause, 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 : SelectJoinClause { | ||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "JOIN", bucket, onKeys) | ||
} | ||
|
||
class LeftJoinClause : SelectJoinClause { | ||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "LEFT JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "LEFT JOIN", bucket, onKeys) | ||
} | ||
|
||
class InnerJoinClause : SelectJoinClause { | ||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "INNER JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "INNER JOIN", bucket, onKeys) | ||
} | ||
|
||
class RightJoinClause : SelectJoinClause { | ||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression<BooleanType>) : | ||
super(parentClause, "RIGHT JOIN", bucket, onCondition) | ||
|
||
constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field<out ValidType>) : | ||
super(parentClause, "RIGHT JOIN", bucket, onKeys) | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/LimitClause.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,21 @@ | ||
package ch.ergon.dope.resolvable.clause.model | ||
|
||
import ch.ergon.dope.resolvable.clause.IDeleteLimitClass | ||
import ch.ergon.dope.resolvable.clause.IDeleteWhereClause | ||
import ch.ergon.dope.resolvable.clause.ISelectLimitClause | ||
import ch.ergon.dope.resolvable.clause.ISelectOrderByClause | ||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.formatToQueryString | ||
import ch.ergon.dope.validtype.NumberType | ||
|
||
private const val LIMIT = "LIMIT" | ||
|
||
class SelectLimitClause(private val numberExpression: TypeExpression<NumberType>, private val parentClause: ISelectOrderByClause) : | ||
ISelectLimitClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, LIMIT, numberExpression) | ||
} | ||
|
||
class DeleteLimitClause(private val numberExpression: TypeExpression<NumberType>, private val parentClause: IDeleteWhereClause) : | ||
IDeleteLimitClass { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, LIMIT, numberExpression) | ||
} |
21 changes: 21 additions & 0 deletions
21
core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OffsetClause.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,21 @@ | ||
package ch.ergon.dope.resolvable.clause.model | ||
|
||
import ch.ergon.dope.resolvable.clause.IDeleteLimitClass | ||
import ch.ergon.dope.resolvable.clause.IDeleteOffsetClass | ||
import ch.ergon.dope.resolvable.clause.ISelectLimitClause | ||
import ch.ergon.dope.resolvable.clause.ISelectOffsetClause | ||
import ch.ergon.dope.resolvable.expression.TypeExpression | ||
import ch.ergon.dope.resolvable.formatToQueryString | ||
import ch.ergon.dope.validtype.NumberType | ||
|
||
private const val OFFSET = "OFFSET" | ||
|
||
class SelectOffsetClause(private val numberExpression: TypeExpression<NumberType>, private val parentClause: ISelectLimitClause) : | ||
ISelectOffsetClause { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, OFFSET, numberExpression) | ||
} | ||
|
||
class DeleteOffsetClause(private val numberExpression: TypeExpression<NumberType>, private val parentClause: IDeleteLimitClass) : | ||
IDeleteOffsetClass { | ||
override fun toQueryString(): String = formatToQueryString(parentClause, OFFSET, numberExpression) | ||
} |
Oops, something went wrong.