From 1c4dd8bc010f44bc12d7a7bf00056a2252990bd0 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Mon, 29 Apr 2024 14:09:52 +0200 Subject: [PATCH 1/6] DOPE-209: added DeleteClause --- .../main/kotlin/ch/ergon/dope/QueryBuilder.kt | 4 + .../dope/resolvable/clause/DeleteClause.kt | 49 ++++++++ .../test/kotlin/ch/ergon/dope/DeleteTest.kt | 107 ++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt create mode 100644 core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt diff --git a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt index fc344ce3..c62ea76a 100644 --- a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt +++ b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt @@ -1,5 +1,6 @@ package ch.ergon.dope +import ch.ergon.dope.resolvable.clause.DeleteClause import ch.ergon.dope.resolvable.clause.FromClause import ch.ergon.dope.resolvable.clause.Fromable import ch.ergon.dope.resolvable.clause.SelectClause @@ -8,6 +9,7 @@ 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.Bucket class QueryBuilder { fun select(expression: Expression, vararg expressions: Expression): SelectClause = SelectClause(expression, *expressions) @@ -20,4 +22,6 @@ class QueryBuilder { fun selectRaw(expression: SingleExpression): SelectRawClause = SelectRawClause(expression) fun selectFrom(fromable: Fromable): FromClause = SelectClause(AsteriskExpression()).from(fromable) + + fun deleteFrom(from: Bucket): DeleteClause = DeleteClause(from) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt new file mode 100644 index 00000000..7c091b65 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt @@ -0,0 +1,49 @@ +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.formatToQueryString +import ch.ergon.dope.resolvable.fromable.Bucket +import ch.ergon.dope.validtype.BooleanType +import ch.ergon.dope.validtype.NumberType +import ch.ergon.dope.validtype.ValidType + +interface IDOffsetClass : Clause { + fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parent = this) +} + +interface IDLimitClass : IDOffsetClass { + fun offset(numberExpression: TypeExpression) = DOffsetClause(numberExpression, this) +} + +interface IDWhereClause : IDLimitClass { + fun limit(numberExpression: TypeExpression) = DLimitClause(numberExpression, this) +} + +interface IDeleteClause : IDWhereClause { + fun where(booleanExpression: TypeExpression) = DWhereClause(booleanExpression, this) +} + +class ReturningClause( + private val field: Field, + private vararg val fields: Field, + private val parent: IDOffsetClass, +) : Clause { + override fun toQueryString(): String = formatToQueryString(parent, "RETURNING", field, *fields) +} + +class DOffsetClause(private val numberExpression: TypeExpression, private val parent: IDLimitClass) : IDOffsetClass { + override fun toQueryString(): String = formatToQueryString(parent, "OFFSET", numberExpression) +} + +class DLimitClause(private val numberExpression: TypeExpression, private val parent: IDWhereClause) : IDLimitClass { + override fun toQueryString(): String = formatToQueryString(parent, "LIMIT", numberExpression) +} + +class DWhereClause(private val booleanExpression: TypeExpression, private val parent: IDeleteClause) : IDWhereClause { + override fun toQueryString(): String = formatToQueryString(parent, "WHERE", booleanExpression) +} + +class DeleteClause(private val from: Bucket) : IDeleteClause { + override fun toQueryString(): String = "DELETE FROM ${from.toQueryString()}" +} diff --git a/core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt b/core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt new file mode 100644 index 00000000..76728a28 --- /dev/null +++ b/core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt @@ -0,0 +1,107 @@ +package ch.ergon.dope + +import ch.ergon.dope.helper.someBucket +import ch.ergon.dope.helper.someNumberField +import ch.ergon.dope.helper.someStringField +import ch.ergon.dope.resolvable.expression.unaliased.type.Primitive.Companion.TRUE +import ch.ergon.dope.resolvable.expression.unaliased.type.logical.and +import ch.ergon.dope.resolvable.expression.unaliased.type.relational.isEqualTo +import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType +import junit.framework.TestCase.assertEquals +import kotlin.test.BeforeTest +import kotlin.test.Test + +class DeleteTest { + private lateinit var create: QueryBuilder + + @BeforeTest + fun setup() { + create = QueryBuilder() + } + + @Test + fun `should support delete from`() { + val expected = "DELETE FROM someBucket" + + val actual: String = create + .deleteFrom(someBucket()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with where`() { + val expected = "DELETE FROM someBucket WHERE TRUE" + + val actual: String = create + .deleteFrom(someBucket()) + .where(TRUE) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with limit`() { + val expected = "DELETE FROM someBucket LIMIT 10" + + val actual: String = create + .deleteFrom(someBucket()) + .limit(10.toNumberType()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with offset`() { + val expected = "DELETE FROM someBucket OFFSET 10" + + val actual: String = create + .deleteFrom(someBucket()) + .offset(10.toNumberType()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with returning`() { + val expected = "DELETE FROM someBucket RETURNING stringField" + + val actual: String = create + .deleteFrom(someBucket()) + .returning(someStringField()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with multiple returning`() { + val expected = "DELETE FROM someBucket RETURNING stringField, numberField" + + val actual: String = create + .deleteFrom(someBucket()) + .returning(someStringField(), someNumberField()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete`() { + val expected = "DELETE FROM someBucket WHERE someBucket.age = 2 AND TRUE LIMIT 7 OFFSET 10 RETURNING stringField" + + val actual: String = create + .deleteFrom(someBucket()) + .where(someNumberField("age", someBucket()).isEqualTo(2).and(TRUE)) + .limit(7.toNumberType()) + .offset(10.toNumberType()) + .returning(someStringField()) + .build() + + assertEquals(expected, actual) + } +} From 6776db92e29b3e44de73d38accb0496bd2016875 Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Mon, 29 Apr 2024 14:09:52 +0200 Subject: [PATCH 2/6] DOPE-209: added DeleteClause --- .../main/kotlin/ch/ergon/dope/QueryBuilder.kt | 4 + .../dope/resolvable/clause/DeleteClause.kt | 49 ++++++++ .../test/kotlin/ch/ergon/dope/DeleteTest.kt | 107 ++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt create mode 100644 core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt diff --git a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt index aa4afff7..59827456 100644 --- a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt +++ b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt @@ -1,5 +1,6 @@ package ch.ergon.dope +import ch.ergon.dope.resolvable.clause.DeleteClause import ch.ergon.dope.resolvable.clause.FromClause import ch.ergon.dope.resolvable.clause.SelectClause import ch.ergon.dope.resolvable.clause.SelectDistinctClause @@ -8,6 +9,7 @@ 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 +import ch.ergon.dope.resolvable.fromable.Bucket class QueryBuilder { fun select(expression: Expression, vararg expressions: Expression): SelectClause = SelectClause(expression, *expressions) @@ -20,4 +22,6 @@ class QueryBuilder { fun selectRaw(expression: SingleExpression): SelectRawClause = SelectRawClause(expression) fun selectFrom(fromable: Fromable): FromClause = SelectClause(AsteriskExpression()).from(fromable) + + fun deleteFrom(from: Bucket): DeleteClause = DeleteClause(from) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt new file mode 100644 index 00000000..7c091b65 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt @@ -0,0 +1,49 @@ +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.formatToQueryString +import ch.ergon.dope.resolvable.fromable.Bucket +import ch.ergon.dope.validtype.BooleanType +import ch.ergon.dope.validtype.NumberType +import ch.ergon.dope.validtype.ValidType + +interface IDOffsetClass : Clause { + fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parent = this) +} + +interface IDLimitClass : IDOffsetClass { + fun offset(numberExpression: TypeExpression) = DOffsetClause(numberExpression, this) +} + +interface IDWhereClause : IDLimitClass { + fun limit(numberExpression: TypeExpression) = DLimitClause(numberExpression, this) +} + +interface IDeleteClause : IDWhereClause { + fun where(booleanExpression: TypeExpression) = DWhereClause(booleanExpression, this) +} + +class ReturningClause( + private val field: Field, + private vararg val fields: Field, + private val parent: IDOffsetClass, +) : Clause { + override fun toQueryString(): String = formatToQueryString(parent, "RETURNING", field, *fields) +} + +class DOffsetClause(private val numberExpression: TypeExpression, private val parent: IDLimitClass) : IDOffsetClass { + override fun toQueryString(): String = formatToQueryString(parent, "OFFSET", numberExpression) +} + +class DLimitClause(private val numberExpression: TypeExpression, private val parent: IDWhereClause) : IDLimitClass { + override fun toQueryString(): String = formatToQueryString(parent, "LIMIT", numberExpression) +} + +class DWhereClause(private val booleanExpression: TypeExpression, private val parent: IDeleteClause) : IDWhereClause { + override fun toQueryString(): String = formatToQueryString(parent, "WHERE", booleanExpression) +} + +class DeleteClause(private val from: Bucket) : IDeleteClause { + override fun toQueryString(): String = "DELETE FROM ${from.toQueryString()}" +} diff --git a/core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt b/core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt new file mode 100644 index 00000000..76728a28 --- /dev/null +++ b/core/src/test/kotlin/ch/ergon/dope/DeleteTest.kt @@ -0,0 +1,107 @@ +package ch.ergon.dope + +import ch.ergon.dope.helper.someBucket +import ch.ergon.dope.helper.someNumberField +import ch.ergon.dope.helper.someStringField +import ch.ergon.dope.resolvable.expression.unaliased.type.Primitive.Companion.TRUE +import ch.ergon.dope.resolvable.expression.unaliased.type.logical.and +import ch.ergon.dope.resolvable.expression.unaliased.type.relational.isEqualTo +import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType +import junit.framework.TestCase.assertEquals +import kotlin.test.BeforeTest +import kotlin.test.Test + +class DeleteTest { + private lateinit var create: QueryBuilder + + @BeforeTest + fun setup() { + create = QueryBuilder() + } + + @Test + fun `should support delete from`() { + val expected = "DELETE FROM someBucket" + + val actual: String = create + .deleteFrom(someBucket()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with where`() { + val expected = "DELETE FROM someBucket WHERE TRUE" + + val actual: String = create + .deleteFrom(someBucket()) + .where(TRUE) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with limit`() { + val expected = "DELETE FROM someBucket LIMIT 10" + + val actual: String = create + .deleteFrom(someBucket()) + .limit(10.toNumberType()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with offset`() { + val expected = "DELETE FROM someBucket OFFSET 10" + + val actual: String = create + .deleteFrom(someBucket()) + .offset(10.toNumberType()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with returning`() { + val expected = "DELETE FROM someBucket RETURNING stringField" + + val actual: String = create + .deleteFrom(someBucket()) + .returning(someStringField()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete from with multiple returning`() { + val expected = "DELETE FROM someBucket RETURNING stringField, numberField" + + val actual: String = create + .deleteFrom(someBucket()) + .returning(someStringField(), someNumberField()) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support delete`() { + val expected = "DELETE FROM someBucket WHERE someBucket.age = 2 AND TRUE LIMIT 7 OFFSET 10 RETURNING stringField" + + val actual: String = create + .deleteFrom(someBucket()) + .where(someNumberField("age", someBucket()).isEqualTo(2).and(TRUE)) + .limit(7.toNumberType()) + .offset(10.toNumberType()) + .returning(someStringField()) + .build() + + assertEquals(expected, actual) + } +} From 2c2ebbafd4e794f384443791020805a9507fcafb Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 3 May 2024 12:11:25 +0200 Subject: [PATCH 3/6] DOPE-209: moved classes into file and extract string for similar classes --- .../main/kotlin/ch/ergon/dope/QueryBuilder.kt | 2 +- .../dope/resolvable/clause/DeleteClause.kt | 42 ----------------- .../dope/resolvable/clause/FromClause.kt | 8 ++++ .../dope/resolvable/clause/GroupByClause.kt | 13 +++++ .../dope/resolvable/clause/IDeleteClause.kt | 23 +++++++++ .../dope/resolvable/clause/LimitClause.kt | 18 +++++++ .../dope/resolvable/clause/OffsetClause.kt | 16 +++++++ .../dope/resolvable/clause/OrderByClause.kt | 23 +++++++++ .../dope/resolvable/clause/OrderByType.kt | 6 --- .../dope/resolvable/clause/ReturningClause.kt | 13 +++++ .../dope/resolvable/clause/SelectClause.kt | 47 +------------------ .../dope/resolvable/clause/WhereClause.kt | 17 +++++++ 12 files changed, 134 insertions(+), 94 deletions(-) create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt delete mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByType.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt diff --git a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt index 59827456..472d34f7 100644 --- a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt +++ b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt @@ -8,8 +8,8 @@ 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 import ch.ergon.dope.resolvable.fromable.Bucket +import ch.ergon.dope.resolvable.fromable.Fromable class QueryBuilder { fun select(expression: Expression, vararg expressions: Expression): SelectClause = SelectClause(expression, *expressions) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt index 7c091b65..5a18e6b5 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt @@ -1,48 +1,6 @@ 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.formatToQueryString import ch.ergon.dope.resolvable.fromable.Bucket -import ch.ergon.dope.validtype.BooleanType -import ch.ergon.dope.validtype.NumberType -import ch.ergon.dope.validtype.ValidType - -interface IDOffsetClass : Clause { - fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parent = this) -} - -interface IDLimitClass : IDOffsetClass { - fun offset(numberExpression: TypeExpression) = DOffsetClause(numberExpression, this) -} - -interface IDWhereClause : IDLimitClass { - fun limit(numberExpression: TypeExpression) = DLimitClause(numberExpression, this) -} - -interface IDeleteClause : IDWhereClause { - fun where(booleanExpression: TypeExpression) = DWhereClause(booleanExpression, this) -} - -class ReturningClause( - private val field: Field, - private vararg val fields: Field, - private val parent: IDOffsetClass, -) : Clause { - override fun toQueryString(): String = formatToQueryString(parent, "RETURNING", field, *fields) -} - -class DOffsetClause(private val numberExpression: TypeExpression, private val parent: IDLimitClass) : IDOffsetClass { - override fun toQueryString(): String = formatToQueryString(parent, "OFFSET", numberExpression) -} - -class DLimitClause(private val numberExpression: TypeExpression, private val parent: IDWhereClause) : IDLimitClass { - override fun toQueryString(): String = formatToQueryString(parent, "LIMIT", numberExpression) -} - -class DWhereClause(private val booleanExpression: TypeExpression, private val parent: IDeleteClause) : IDWhereClause { - override fun toQueryString(): String = formatToQueryString(parent, "WHERE", booleanExpression) -} class DeleteClause(private val from: Bucket) : IDeleteClause { override fun toQueryString(): String = "DELETE FROM ${from.toQueryString()}" diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt new file mode 100644 index 00000000..c2af8aa3 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt @@ -0,0 +1,8 @@ +package ch.ergon.dope.resolvable.clause + +import ch.ergon.dope.resolvable.formatToQueryString +import ch.ergon.dope.resolvable.fromable.Fromable + +class FromClause(private val fromable: Fromable, private val parentClause: ISelectClause) : IJoinClause { + override fun toQueryString(): String = formatToQueryString(parentClause, "FROM", fromable) +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt new file mode 100644 index 00000000..7ee874bb --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt @@ -0,0 +1,13 @@ +package ch.ergon.dope.resolvable.clause + +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, + private vararg val fields: Field, + private val parentClause: IWhereClause, +) : IGroupByClause { + override fun toQueryString(): String = formatToQueryString(parentClause, "GROUP BY", field, *fields) +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt new file mode 100644 index 00000000..c1d47d87 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt @@ -0,0 +1,23 @@ +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.validtype.BooleanType +import ch.ergon.dope.validtype.NumberType +import ch.ergon.dope.validtype.ValidType + +interface IDeleteOffsetClass : Clause { + fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parent = this) +} + +interface IDeleteLimitClass : IDeleteOffsetClass { + fun offset(numberExpression: TypeExpression) = DeleteOffsetClause(numberExpression, this) +} + +interface IDeleteWhereClause : IDeleteLimitClass { + fun limit(numberExpression: TypeExpression) = DeleteLimitClause(numberExpression, this) +} + +interface IDeleteClause : IDeleteWhereClause { + fun where(booleanExpression: TypeExpression) = DeleteWhereClause(booleanExpression, this) +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt new file mode 100644 index 00000000..98142377 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt @@ -0,0 +1,18 @@ +package ch.ergon.dope.resolvable.clause + +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 LimitClause(private val numberExpression: TypeExpression, private val parentClause: IOrderByClause) : ILimitClause { + override fun toQueryString(): String = formatToQueryString(parentClause, LIMIT, numberExpression) +} + +class DeleteLimitClause(private val numberExpression: TypeExpression, private val parent: IDeleteWhereClause) : + IDeleteLimitClass { + override fun toQueryString(): String { + return formatToQueryString(parent, LIMIT, numberExpression) + } +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt new file mode 100644 index 00000000..dbb81feb --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt @@ -0,0 +1,16 @@ +package ch.ergon.dope.resolvable.clause + +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 OffsetClause(private val numberExpression: TypeExpression, private val parentClause: ILimitClause) : IOffsetClause { + override fun toQueryString(): String = formatToQueryString(parentClause, OFFSET, numberExpression) +} + +class DeleteOffsetClause(private val numberExpression: TypeExpression, private val parent: IDeleteLimitClass) : + IDeleteOffsetClass { + override fun toQueryString(): String = formatToQueryString(parent, OFFSET, numberExpression) +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt new file mode 100644 index 00000000..b7f0feab --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt @@ -0,0 +1,23 @@ +package ch.ergon.dope.resolvable.clause + +import ch.ergon.dope.resolvable.expression.unaliased.type.Field +import ch.ergon.dope.resolvable.formatToQueryString +import ch.ergon.dope.validtype.StringType + +enum class OrderByType(val type: String) { + ASC("ASC"), + DESC("DESC"), +} + +open class OrderByClause(private val stringField: Field, private val parentClause: IGroupByClause) : + IOrderByClause { + override fun toQueryString(): String = formatToQueryString(parentClause, "ORDER BY", stringField) +} + +class OrderByTypeClause( + stringField: Field, + private val orderByType: OrderByType, + parentClause: IGroupByClause, +) : OrderByClause(stringField, parentClause) { + override fun toQueryString(): String = super.toQueryString() + " ${orderByType.type}" +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByType.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByType.kt deleted file mode 100644 index 7d4d6d9c..00000000 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByType.kt +++ /dev/null @@ -1,6 +0,0 @@ -package ch.ergon.dope.resolvable.clause - -enum class OrderByType(val type: String) { - ASC("ASC"), - DESC("DESC"), -} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt new file mode 100644 index 00000000..9408a561 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt @@ -0,0 +1,13 @@ +package ch.ergon.dope.resolvable.clause + +import ch.ergon.dope.resolvable.expression.unaliased.type.Field +import ch.ergon.dope.resolvable.formatToQueryString +import ch.ergon.dope.validtype.ValidType + +class ReturningClause( + private val field: Field, + private vararg val fields: Field, + private val parent: IDeleteOffsetClass, +) : Clause { + override fun toQueryString(): String = formatToQueryString(parent, "RETURNING", field, *fields) +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt index f806d4ea..cd24747e 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt @@ -1,49 +1,10 @@ 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, private val parentClause: ILimitClause) : IOffsetClause { - override fun toQueryString(): String = formatToQueryString(parentClause, "OFFSET", numberExpression) -} - -class LimitClause(private val numberExpression: TypeExpression, private val parentClause: IOrderByClause) : ILimitClause { - override fun toQueryString(): String = formatToQueryString(parentClause, "LIMIT", numberExpression) -} - -open class OrderByClause(private val stringField: Field, private val parentClause: IGroupByClause) : IOrderByClause { - override fun toQueryString(): String = formatToQueryString(parentClause, "ORDER BY", stringField) -} - -class OrderByTypeClause( - stringField: Field, - private val orderByType: OrderByType, - parentClause: IGroupByClause, -) : OrderByClause(stringField, parentClause) { - override fun toQueryString(): String = super.toQueryString() + " ${orderByType.type}" -} - -class GroupByClause( - private val field: Field, - private vararg val fields: Field, - private val parentClause: IWhereClause, -) : IGroupByClause { - override fun toQueryString(): String = formatToQueryString(parentClause, "GROUP BY", field, *fields) -} - -class WhereClause(private val whereExpression: TypeExpression, 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 SelectClause(private val expression: Expression, private vararg val expressions: Expression) : ISelectClause { + override fun toQueryString(): String = formatToQueryString("SELECT", expression, *expressions) } class SelectRawClause(private val expression: Expression) : ISelectClause { @@ -53,7 +14,3 @@ class SelectRawClause(private val expression: Expression) : ISelectClause { 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) -} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt new file mode 100644 index 00000000..570861c5 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt @@ -0,0 +1,17 @@ +package ch.ergon.dope.resolvable.clause + +import ch.ergon.dope.resolvable.expression.TypeExpression +import ch.ergon.dope.resolvable.formatToQueryString +import ch.ergon.dope.validtype.BooleanType + +private const val WHERE = "WHERE" + +class WhereClause(private val whereExpression: TypeExpression, private val parentClause: IFromClause) : IWhereClause { + override fun toQueryString(): String = formatToQueryString(parentClause, WHERE, whereExpression) +} + +class DeleteWhereClause(private val booleanExpression: TypeExpression, private val parent: IDeleteClause) : IDeleteWhereClause { + override fun toQueryString(): String { + return formatToQueryString(parent, WHERE, booleanExpression) + } +} From 908239d6798d927a9f34c7ba0df8094ee4e2ae2d Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 3 May 2024 13:21:37 +0200 Subject: [PATCH 4/6] DOPE-209: added IReturningClause --- .../kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt | 4 +++- .../kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt index c1d47d87..91ca2b6c 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt @@ -6,7 +6,9 @@ import ch.ergon.dope.validtype.BooleanType import ch.ergon.dope.validtype.NumberType import ch.ergon.dope.validtype.ValidType -interface IDeleteOffsetClass : Clause { +interface IReturningClause : Clause + +interface IDeleteOffsetClass : IReturningClause { fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parent = this) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt index 9408a561..53b763cd 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt @@ -8,6 +8,6 @@ class ReturningClause( private val field: Field, private vararg val fields: Field, private val parent: IDeleteOffsetClass, -) : Clause { +) : IReturningClause { override fun toQueryString(): String = formatToQueryString(parent, "RETURNING", field, *fields) } From ec9d4d78ac04b10f2b726e049364d4474950bd0e Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 3 May 2024 13:35:01 +0200 Subject: [PATCH 5/6] DOPE-209: renaming --- core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt | 2 +- .../ch/ergon/dope/resolvable/clause/DeleteClause.kt | 4 ++-- .../ch/ergon/dope/resolvable/clause/IDeleteClause.kt | 2 +- .../ch/ergon/dope/resolvable/clause/ISelectClause.kt | 8 ++++---- .../ch/ergon/dope/resolvable/clause/LimitClause.kt | 8 +++----- .../ch/ergon/dope/resolvable/clause/OffsetClause.kt | 6 +++--- .../ch/ergon/dope/resolvable/clause/ReturningClause.kt | 4 ++-- .../clause/{WhereClause.kt => SelectWhereClause.kt} | 9 ++++----- .../main/kotlin/ch/ergon/dope/extension/clause/Select.kt | 8 ++++---- 9 files changed, 24 insertions(+), 27 deletions(-) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{WhereClause.kt => SelectWhereClause.kt} (54%) diff --git a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt index 472d34f7..61d9239a 100644 --- a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt +++ b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt @@ -23,5 +23,5 @@ class QueryBuilder { fun selectFrom(fromable: Fromable): FromClause = SelectClause(AsteriskExpression()).from(fromable) - fun deleteFrom(from: Bucket): DeleteClause = DeleteClause(from) + fun deleteFrom(bucket: Bucket): DeleteClause = DeleteClause(bucket) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt index 5a18e6b5..2845c62d 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt @@ -2,6 +2,6 @@ package ch.ergon.dope.resolvable.clause import ch.ergon.dope.resolvable.fromable.Bucket -class DeleteClause(private val from: Bucket) : IDeleteClause { - override fun toQueryString(): String = "DELETE FROM ${from.toQueryString()}" +class DeleteClause(private val bucket: Bucket) : IDeleteClause { + override fun toQueryString(): String = "DELETE FROM ${bucket.toQueryString()}" } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt index 91ca2b6c..a9591324 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt @@ -9,7 +9,7 @@ import ch.ergon.dope.validtype.ValidType interface IReturningClause : Clause interface IDeleteOffsetClass : IReturningClause { - fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parent = this) + fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parentClause = this) } interface IDeleteLimitClass : IDeleteOffsetClass { diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt index c08a65cb..e8ac907c 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt @@ -14,12 +14,12 @@ import ch.ergon.dope.validtype.ValidType interface IOffsetClause : Clause interface ILimitClause : IOffsetClause { - fun offset(numberExpression: TypeExpression): OffsetClause = OffsetClause(numberExpression, this) + fun offset(numberExpression: TypeExpression): SelectOffsetClause = SelectOffsetClause(numberExpression, this) } interface IOrderByClause : ILimitClause { - fun limit(numberExpression: TypeExpression): LimitClause = LimitClause(numberExpression, this) - fun limit(number: Number): LimitClause = limit(number.toNumberType()) + fun limit(numberExpression: TypeExpression): SelectLimitClause = SelectLimitClause(numberExpression, this) + fun limit(number: Number): SelectLimitClause = limit(number.toNumberType()) } interface IGroupByClause : IOrderByClause { @@ -33,7 +33,7 @@ interface IWhereClause : IGroupByClause { } interface IFromClause : IWhereClause { - fun where(whereExpression: TypeExpression) = WhereClause(whereExpression, this) + fun where(whereExpression: TypeExpression) = SelectWhereClause(whereExpression, this) } interface IJoinClause : IFromClause { diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt index 98142377..7e234378 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt @@ -6,13 +6,11 @@ import ch.ergon.dope.validtype.NumberType private const val LIMIT = "LIMIT" -class LimitClause(private val numberExpression: TypeExpression, private val parentClause: IOrderByClause) : ILimitClause { +class SelectLimitClause(private val numberExpression: TypeExpression, private val parentClause: IOrderByClause) : ILimitClause { override fun toQueryString(): String = formatToQueryString(parentClause, LIMIT, numberExpression) } -class DeleteLimitClause(private val numberExpression: TypeExpression, private val parent: IDeleteWhereClause) : +class DeleteLimitClause(private val numberExpression: TypeExpression, private val parentClause: IDeleteWhereClause) : IDeleteLimitClass { - override fun toQueryString(): String { - return formatToQueryString(parent, LIMIT, numberExpression) - } + override fun toQueryString(): String = formatToQueryString(parentClause, LIMIT, numberExpression) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt index dbb81feb..fc50c474 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt @@ -6,11 +6,11 @@ import ch.ergon.dope.validtype.NumberType private const val OFFSET = "OFFSET" -class OffsetClause(private val numberExpression: TypeExpression, private val parentClause: ILimitClause) : IOffsetClause { +class SelectOffsetClause(private val numberExpression: TypeExpression, private val parentClause: ILimitClause) : IOffsetClause { override fun toQueryString(): String = formatToQueryString(parentClause, OFFSET, numberExpression) } -class DeleteOffsetClause(private val numberExpression: TypeExpression, private val parent: IDeleteLimitClass) : +class DeleteOffsetClause(private val numberExpression: TypeExpression, private val parentClause: IDeleteLimitClass) : IDeleteOffsetClass { - override fun toQueryString(): String = formatToQueryString(parent, OFFSET, numberExpression) + override fun toQueryString(): String = formatToQueryString(parentClause, OFFSET, numberExpression) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt index 53b763cd..17ab5502 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt @@ -7,7 +7,7 @@ import ch.ergon.dope.validtype.ValidType class ReturningClause( private val field: Field, private vararg val fields: Field, - private val parent: IDeleteOffsetClass, + private val parentClause: IDeleteOffsetClass, ) : IReturningClause { - override fun toQueryString(): String = formatToQueryString(parent, "RETURNING", field, *fields) + override fun toQueryString(): String = formatToQueryString(parentClause, "RETURNING", field, *fields) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectWhereClause.kt similarity index 54% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectWhereClause.kt index 570861c5..06274df7 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/WhereClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectWhereClause.kt @@ -6,12 +6,11 @@ import ch.ergon.dope.validtype.BooleanType private const val WHERE = "WHERE" -class WhereClause(private val whereExpression: TypeExpression, private val parentClause: IFromClause) : IWhereClause { +class SelectWhereClause(private val whereExpression: TypeExpression, private val parentClause: IFromClause) : IWhereClause { override fun toQueryString(): String = formatToQueryString(parentClause, WHERE, whereExpression) } -class DeleteWhereClause(private val booleanExpression: TypeExpression, private val parent: IDeleteClause) : IDeleteWhereClause { - override fun toQueryString(): String { - return formatToQueryString(parent, WHERE, booleanExpression) - } +class DeleteWhereClause(private val booleanExpression: TypeExpression, private val parentClause: IDeleteClause) : + IDeleteWhereClause { + override fun toQueryString(): String = formatToQueryString(parentClause, WHERE, booleanExpression) } diff --git a/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt b/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt index f7e51ff2..fed67e56 100644 --- a/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt +++ b/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt @@ -4,15 +4,15 @@ import ch.ergon.dope.asField import ch.ergon.dope.resolvable.clause.IGroupByClause import ch.ergon.dope.resolvable.clause.ILimitClause import ch.ergon.dope.resolvable.clause.IOrderByClause -import ch.ergon.dope.resolvable.clause.LimitClause -import ch.ergon.dope.resolvable.clause.OffsetClause import ch.ergon.dope.resolvable.clause.OrderByClause import ch.ergon.dope.resolvable.clause.OrderByType +import ch.ergon.dope.resolvable.clause.SelectLimitClause +import ch.ergon.dope.resolvable.clause.SelectOffsetClause import com.schwarz.crystalapi.schema.CMField -fun ILimitClause.offset(numberField: CMField): OffsetClause = offset(numberField.asField()) +fun ILimitClause.offset(numberField: CMField): SelectOffsetClause = offset(numberField.asField()) -fun IOrderByClause.limit(numberField: CMField): LimitClause = limit(numberField.asField()) +fun IOrderByClause.limit(numberField: CMField): SelectLimitClause = limit(numberField.asField()) fun IGroupByClause.orderBy(stringField: CMField, orderByType: OrderByType): OrderByClause = orderBy(stringField.asField(), orderByType) From 90ef6a703a20d2a12c87a636d27238b329f45dbe Mon Sep 17 00:00:00 2001 From: Jan Sigrist Date: Fri, 3 May 2024 14:10:52 +0200 Subject: [PATCH 6/6] DOPE-209: moved all classes into model-package, renaming --- .../main/kotlin/ch/ergon/dope/QueryBuilder.kt | 10 ++-- .../dope/resolvable/clause/IDeleteClause.kt | 11 +++- .../dope/resolvable/clause/ISelectClause.kt | 34 ++++++++---- .../dope/resolvable/clause/JoinClause.kt | 53 ------------------ .../clause/{ => model}/DeleteClause.kt | 3 +- .../clause/{ => model}/FromClause.kt | 6 +- .../clause/{ => model}/GroupByClause.kt | 8 ++- .../resolvable/clause/model/JoinClause.kt | 55 +++++++++++++++++++ .../clause/{ => model}/LimitClause.kt | 9 ++- .../clause/{ => model}/OffsetClause.kt | 9 ++- .../clause/{ => model}/OrderByClause.kt | 14 +++-- .../clause/{ => model}/ReturningClause.kt | 6 +- .../clause/{ => model}/SelectClause.kt | 3 +- .../WhereClause.kt} | 9 ++- .../test/kotlin/ch/ergon/dope/OrderByTest.kt | 2 +- .../ch/ergon/dope/extension/clause/Select.kt | 23 ++++---- 16 files changed, 152 insertions(+), 103 deletions(-) delete mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/JoinClause.kt rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/DeleteClause.kt (66%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/FromClause.kt (56%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/GroupByClause.kt (61%) create mode 100644 core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/JoinClause.kt rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/LimitClause.kt (62%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/OffsetClause.kt (62%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/OrderByClause.kt (53%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/ReturningClause.kt (69%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{ => model}/SelectClause.kt (88%) rename core/src/main/kotlin/ch/ergon/dope/resolvable/clause/{SelectWhereClause.kt => model/WhereClause.kt} (62%) diff --git a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt index 61d9239a..d9e4a9f0 100644 --- a/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt +++ b/core/src/main/kotlin/ch/ergon/dope/QueryBuilder.kt @@ -1,10 +1,10 @@ package ch.ergon.dope -import ch.ergon.dope.resolvable.clause.DeleteClause -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.clause.model.DeleteClause +import ch.ergon.dope.resolvable.clause.model.FromClause +import ch.ergon.dope.resolvable.clause.model.SelectClause +import ch.ergon.dope.resolvable.clause.model.SelectDistinctClause +import ch.ergon.dope.resolvable.clause.model.SelectRawClause import ch.ergon.dope.resolvable.expression.AsteriskExpression import ch.ergon.dope.resolvable.expression.Expression import ch.ergon.dope.resolvable.expression.SingleExpression diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt index a9591324..6cba056f 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/IDeleteClause.kt @@ -1,23 +1,30 @@ 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 IReturningClause : Clause +interface IDeleteReturningClause : Clause -interface IDeleteOffsetClass : IReturningClause { +interface IDeleteOffsetClass : IDeleteReturningClause { fun returning(field: Field, vararg fields: Field) = ReturningClause(field, *fields, parentClause = this) } interface IDeleteLimitClass : IDeleteOffsetClass { fun offset(numberExpression: TypeExpression) = DeleteOffsetClause(numberExpression, this) + fun offset(number: Number): DeleteOffsetClause = offset(number.toNumberType()) } interface IDeleteWhereClause : IDeleteLimitClass { fun limit(numberExpression: TypeExpression) = DeleteLimitClause(numberExpression, this) + fun limit(number: Number): DeleteLimitClause = limit(number.toNumberType()) } interface IDeleteClause : IDeleteWhereClause { diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt index e8ac907c..59eaaedd 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ISelectClause.kt @@ -1,5 +1,17 @@ package ch.ergon.dope.resolvable.clause +import ch.ergon.dope.resolvable.clause.model.FromClause +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.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.expression.TypeExpression import ch.ergon.dope.resolvable.expression.unaliased.type.Field import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType @@ -11,32 +23,34 @@ import ch.ergon.dope.validtype.NumberType import ch.ergon.dope.validtype.StringType import ch.ergon.dope.validtype.ValidType -interface IOffsetClause : Clause +interface ISelectOffsetClause : Clause -interface ILimitClause : IOffsetClause { +interface ISelectLimitClause : ISelectOffsetClause { fun offset(numberExpression: TypeExpression): SelectOffsetClause = SelectOffsetClause(numberExpression, this) + fun offset(number: Number): SelectOffsetClause = offset(number.toNumberType()) } -interface IOrderByClause : ILimitClause { +interface ISelectOrderByClause : ISelectLimitClause { fun limit(numberExpression: TypeExpression): SelectLimitClause = SelectLimitClause(numberExpression, this) fun limit(number: Number): SelectLimitClause = limit(number.toNumberType()) } -interface IGroupByClause : IOrderByClause { - fun orderBy(stringField: Field): OrderByClause = OrderByClause(stringField, this) - fun orderBy(stringField: Field, orderByType: OrderByType): OrderByTypeClause = OrderByTypeClause(stringField, orderByType, this) +interface ISelectGroupByClause : ISelectOrderByClause { + fun orderBy(stringField: Field): SelectOrderByClause = SelectOrderByClause(stringField, this) + fun orderBy(stringField: Field, orderByType: OrderByType): SelectOrderByTypeClause = + SelectOrderByTypeClause(stringField, orderByType, this) } -interface IWhereClause : IGroupByClause { +interface ISelectWhereClause : ISelectGroupByClause { fun groupBy(field: Field, vararg fields: Field): GroupByClause = GroupByClause(field, *fields, parentClause = this) } -interface IFromClause : IWhereClause { +interface ISelectFromClause : ISelectWhereClause { fun where(whereExpression: TypeExpression) = SelectWhereClause(whereExpression, this) } -interface IJoinClause : IFromClause { +interface ISelectJoinClause : ISelectFromClause { fun join(bucket: Bucket, onCondition: TypeExpression) = StandardJoinClause(this, bucket, onCondition) fun join(bucket: Bucket, onKeys: Field) = StandardJoinClause(this, bucket, onKeys) @@ -50,7 +64,7 @@ interface IJoinClause : IFromClause { fun rightJoin(bucket: Bucket, onKeys: Field) = RightJoinClause(this, bucket, onKeys) } -interface ISelectClause : IFromClause { +interface ISelectClause : ISelectFromClause { fun from(fromable: Fromable) = FromClause(fromable, this) fun alias(alias: String) = AliasedSelectClause(alias, this) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/JoinClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/JoinClause.kt deleted file mode 100644 index 07129c76..00000000 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/JoinClause.kt +++ /dev/null @@ -1,53 +0,0 @@ -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) { - queryString = "${parentClause.toQueryString()} $joinType ${bucket.toQueryString()} ON ${onCondition.toQueryString()}" - } - - constructor(parentClause: IFromClause, joinType: String, bucket: Bucket, key: Field) { - 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) : - super(parentClause, "JOIN", bucket, onCondition) - - constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field) : - super(parentClause, "JOIN", bucket, onKeys) -} - -class LeftJoinClause : JoinClause { - constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression) : - super(parentClause, "LEFT JOIN", bucket, onCondition) - - constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field) : - super(parentClause, "LEFT JOIN", bucket, onKeys) -} - -class InnerJoinClause : JoinClause { - constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression) : - super(parentClause, "INNER JOIN", bucket, onCondition) - - constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field) : - super(parentClause, "INNER JOIN", bucket, onKeys) -} - -class RightJoinClause : JoinClause { - constructor(parentClause: IFromClause, bucket: Bucket, onCondition: TypeExpression) : - super(parentClause, "RIGHT JOIN", bucket, onCondition) - - constructor(parentClause: IFromClause, bucket: Bucket, onKeys: Field) : - super(parentClause, "RIGHT JOIN", bucket, onKeys) -} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/DeleteClause.kt similarity index 66% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/DeleteClause.kt index 2845c62d..e36665b3 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/DeleteClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/DeleteClause.kt @@ -1,5 +1,6 @@ -package ch.ergon.dope.resolvable.clause +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 { diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/FromClause.kt similarity index 56% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/FromClause.kt index c2af8aa3..d1f33aae 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/FromClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/FromClause.kt @@ -1,8 +1,10 @@ -package ch.ergon.dope.resolvable.clause +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) : IJoinClause { +class FromClause(private val fromable: Fromable, private val parentClause: ISelectClause) : ISelectJoinClause { override fun toQueryString(): String = formatToQueryString(parentClause, "FROM", fromable) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/GroupByClause.kt similarity index 61% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/GroupByClause.kt index 7ee874bb..4d4ae09e 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/GroupByClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/GroupByClause.kt @@ -1,5 +1,7 @@ -package ch.ergon.dope.resolvable.clause +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 @@ -7,7 +9,7 @@ import ch.ergon.dope.validtype.ValidType class GroupByClause( private val field: Field, private vararg val fields: Field, - private val parentClause: IWhereClause, -) : IGroupByClause { + private val parentClause: ISelectWhereClause, +) : ISelectGroupByClause { override fun toQueryString(): String = formatToQueryString(parentClause, "GROUP BY", field, *fields) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/JoinClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/JoinClause.kt new file mode 100644 index 00000000..5b3a55b0 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/JoinClause.kt @@ -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) { + queryString = "${parentClause.toQueryString()} $joinType ${bucket.toQueryString()} ON ${onCondition.toQueryString()}" + } + + constructor(parentClause: ISelectFromClause, joinType: String, bucket: Bucket, key: Field) { + 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) : + super(parentClause, "JOIN", bucket, onCondition) + + constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field) : + super(parentClause, "JOIN", bucket, onKeys) +} + +class LeftJoinClause : SelectJoinClause { + constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression) : + super(parentClause, "LEFT JOIN", bucket, onCondition) + + constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field) : + super(parentClause, "LEFT JOIN", bucket, onKeys) +} + +class InnerJoinClause : SelectJoinClause { + constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression) : + super(parentClause, "INNER JOIN", bucket, onCondition) + + constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field) : + super(parentClause, "INNER JOIN", bucket, onKeys) +} + +class RightJoinClause : SelectJoinClause { + constructor(parentClause: ISelectFromClause, bucket: Bucket, onCondition: TypeExpression) : + super(parentClause, "RIGHT JOIN", bucket, onCondition) + + constructor(parentClause: ISelectFromClause, bucket: Bucket, onKeys: Field) : + super(parentClause, "RIGHT JOIN", bucket, onKeys) +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/LimitClause.kt similarity index 62% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/LimitClause.kt index 7e234378..c8111af4 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/LimitClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/LimitClause.kt @@ -1,12 +1,17 @@ -package ch.ergon.dope.resolvable.clause +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, private val parentClause: IOrderByClause) : ILimitClause { +class SelectLimitClause(private val numberExpression: TypeExpression, private val parentClause: ISelectOrderByClause) : + ISelectLimitClause { override fun toQueryString(): String = formatToQueryString(parentClause, LIMIT, numberExpression) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OffsetClause.kt similarity index 62% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OffsetClause.kt index fc50c474..76dad6b3 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OffsetClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OffsetClause.kt @@ -1,12 +1,17 @@ -package ch.ergon.dope.resolvable.clause +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, private val parentClause: ILimitClause) : IOffsetClause { +class SelectOffsetClause(private val numberExpression: TypeExpression, private val parentClause: ISelectLimitClause) : + ISelectOffsetClause { override fun toQueryString(): String = formatToQueryString(parentClause, OFFSET, numberExpression) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OrderByClause.kt similarity index 53% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OrderByClause.kt index b7f0feab..3538d423 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/OrderByClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/OrderByClause.kt @@ -1,5 +1,7 @@ -package ch.ergon.dope.resolvable.clause +package ch.ergon.dope.resolvable.clause.model +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.formatToQueryString import ch.ergon.dope.validtype.StringType @@ -9,15 +11,15 @@ enum class OrderByType(val type: String) { DESC("DESC"), } -open class OrderByClause(private val stringField: Field, private val parentClause: IGroupByClause) : - IOrderByClause { +open class SelectOrderByClause(private val stringField: Field, private val parentClause: ISelectGroupByClause) : + ISelectOrderByClause { override fun toQueryString(): String = formatToQueryString(parentClause, "ORDER BY", stringField) } -class OrderByTypeClause( +class SelectOrderByTypeClause( stringField: Field, private val orderByType: OrderByType, - parentClause: IGroupByClause, -) : OrderByClause(stringField, parentClause) { + parentClause: ISelectGroupByClause, +) : SelectOrderByClause(stringField, parentClause) { override fun toQueryString(): String = super.toQueryString() + " ${orderByType.type}" } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/ReturningClause.kt similarity index 69% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/ReturningClause.kt index 17ab5502..9a962cfd 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ReturningClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/ReturningClause.kt @@ -1,5 +1,7 @@ -package ch.ergon.dope.resolvable.clause +package ch.ergon.dope.resolvable.clause.model +import ch.ergon.dope.resolvable.clause.IDeleteOffsetClass +import ch.ergon.dope.resolvable.clause.IDeleteReturningClause import ch.ergon.dope.resolvable.expression.unaliased.type.Field import ch.ergon.dope.resolvable.formatToQueryString import ch.ergon.dope.validtype.ValidType @@ -8,6 +10,6 @@ class ReturningClause( private val field: Field, private vararg val fields: Field, private val parentClause: IDeleteOffsetClass, -) : IReturningClause { +) : IDeleteReturningClause { override fun toQueryString(): String = formatToQueryString(parentClause, "RETURNING", field, *fields) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/SelectClause.kt similarity index 88% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/SelectClause.kt index cd24747e..5535a4ca 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/SelectClause.kt @@ -1,5 +1,6 @@ -package ch.ergon.dope.resolvable.clause +package ch.ergon.dope.resolvable.clause.model +import ch.ergon.dope.resolvable.clause.ISelectClause import ch.ergon.dope.resolvable.expression.Expression import ch.ergon.dope.resolvable.formatToQueryString diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectWhereClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/WhereClause.kt similarity index 62% rename from core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectWhereClause.kt rename to core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/WhereClause.kt index 06274df7..545ee900 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/SelectWhereClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/model/WhereClause.kt @@ -1,12 +1,17 @@ -package ch.ergon.dope.resolvable.clause +package ch.ergon.dope.resolvable.clause.model +import ch.ergon.dope.resolvable.clause.IDeleteClause +import ch.ergon.dope.resolvable.clause.IDeleteWhereClause +import ch.ergon.dope.resolvable.clause.ISelectFromClause +import ch.ergon.dope.resolvable.clause.ISelectWhereClause import ch.ergon.dope.resolvable.expression.TypeExpression import ch.ergon.dope.resolvable.formatToQueryString import ch.ergon.dope.validtype.BooleanType private const val WHERE = "WHERE" -class SelectWhereClause(private val whereExpression: TypeExpression, private val parentClause: IFromClause) : IWhereClause { +class SelectWhereClause(private val whereExpression: TypeExpression, private val parentClause: ISelectFromClause) : + ISelectWhereClause { override fun toQueryString(): String = formatToQueryString(parentClause, WHERE, whereExpression) } diff --git a/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt b/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt index 7086a0e3..b7507da9 100644 --- a/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt @@ -2,7 +2,7 @@ package ch.ergon.dope import ch.ergon.dope.helper.someBucket import ch.ergon.dope.helper.someStringField -import ch.ergon.dope.resolvable.clause.OrderByType +import ch.ergon.dope.resolvable.clause.model.OrderByType import junit.framework.TestCase.assertEquals import kotlin.test.BeforeTest import kotlin.test.Test diff --git a/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt b/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt index fed67e56..890fd3f3 100644 --- a/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt +++ b/crystal-map-connector/src/main/kotlin/ch/ergon/dope/extension/clause/Select.kt @@ -1,19 +1,20 @@ package ch.ergon.dope.extension.clause import ch.ergon.dope.asField -import ch.ergon.dope.resolvable.clause.IGroupByClause -import ch.ergon.dope.resolvable.clause.ILimitClause -import ch.ergon.dope.resolvable.clause.IOrderByClause -import ch.ergon.dope.resolvable.clause.OrderByClause -import ch.ergon.dope.resolvable.clause.OrderByType -import ch.ergon.dope.resolvable.clause.SelectLimitClause -import ch.ergon.dope.resolvable.clause.SelectOffsetClause +import ch.ergon.dope.resolvable.clause.ISelectGroupByClause +import ch.ergon.dope.resolvable.clause.ISelectLimitClause +import ch.ergon.dope.resolvable.clause.ISelectOrderByClause +import ch.ergon.dope.resolvable.clause.model.OrderByType +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 com.schwarz.crystalapi.schema.CMField -fun ILimitClause.offset(numberField: CMField): SelectOffsetClause = offset(numberField.asField()) +fun ISelectLimitClause.offset(numberField: CMField): SelectOffsetClause = offset(numberField.asField()) -fun IOrderByClause.limit(numberField: CMField): SelectLimitClause = limit(numberField.asField()) +fun ISelectOrderByClause.limit(numberField: CMField): SelectLimitClause = limit(numberField.asField()) -fun IGroupByClause.orderBy(stringField: CMField, orderByType: OrderByType): OrderByClause = orderBy(stringField.asField(), orderByType) +fun ISelectGroupByClause.orderBy(stringField: CMField, orderByType: OrderByType): SelectOrderByClause = + orderBy(stringField.asField(), orderByType) -fun IGroupByClause.orderBy(stringField: CMField): OrderByClause = orderBy(stringField.asField()) +fun ISelectGroupByClause.orderBy(stringField: CMField): SelectOrderByClause = orderBy(stringField.asField())