diff --git a/core/src/main/kotlin/ch/ergon/dope/DSLContext.kt b/core/src/main/kotlin/ch/ergon/dope/DSLContext.kt index 82d0a9b4..658bd8c8 100644 --- a/core/src/main/kotlin/ch/ergon/dope/DSLContext.kt +++ b/core/src/main/kotlin/ch/ergon/dope/DSLContext.kt @@ -5,17 +5,18 @@ import ch.ergon.dope.resolvable.clause.select.factory.From import ch.ergon.dope.resolvable.clause.select.factory.Select import ch.ergon.dope.resolvable.clause.select.factory.Where import ch.ergon.dope.resolvable.expression.Expression +import ch.ergon.dope.resolvable.expression.SingleExpression class DSLContext { private val select = Select() fun select(expression: Expression, vararg expressions: Expression): From = select.select(expression, *expressions) - fun selectAll(): From = select.selectAll() + fun selectAsterisk(): From = select.selectAsterisk() fun selectDistinct(expression: Expression, vararg expressions: Expression): From = select.selectDistinct(expression, *expressions) - fun selectRaw(expression: Expression): From = select.selectRaw(expression) + fun selectRaw(expression: SingleExpression): From = select.selectRaw(expression) fun selectFrom(fromable: Fromable): Where = select.selectFrom(fromable) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ClauseBuilder.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ClauseBuilder.kt index bce46f47..a15aa64a 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ClauseBuilder.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/ClauseBuilder.kt @@ -19,7 +19,9 @@ import ch.ergon.dope.resolvable.clause.select.factory.Offset import ch.ergon.dope.resolvable.clause.select.factory.OrderBy import ch.ergon.dope.resolvable.clause.select.factory.OrderByType import ch.ergon.dope.resolvable.clause.select.factory.Where +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.expression.TypeExpression import ch.ergon.dope.resolvable.expression.unaliased.type.Field import ch.ergon.dope.validtype.BooleanType @@ -30,14 +32,14 @@ import ch.ergon.dope.validtype.ValidType class ClauseBuilder(private val clauses: List) { fun select(expression: Expression, vararg expressions: Expression): From = From(addClause(SelectClause(expression, *expressions))) - fun selectAll(): From = From(addClause(SelectClause(AsterisksExpression()))) + fun selectAsterisk(): From = From(addClause(SelectClause(AsteriskExpression()))) fun selectDistinct(expression: Expression, vararg expressions: Expression): From = From(addClause(SelectDistinctClause(expression, *expressions))) - fun selectRaw(expression: Expression): From = From(addClause(SelectRawClause(expression))) + fun selectRaw(expression: SingleExpression): From = From(addClause(SelectRawClause(expression))) - fun selectFrom(fromable: Fromable): Where = ClauseBuilder(addClause(SelectClause(AsterisksExpression()))).from(fromable) + fun selectFrom(fromable: Fromable): Where = ClauseBuilder(addClause(SelectClause(AsteriskExpression()))).from(fromable) fun from(fromable: Fromable): Where = Where(addClause(FromClause(fromable))) @@ -61,7 +63,3 @@ class ClauseBuilder(private val clauses: List) { return clauses + clause } } - -private class AsterisksExpression : Expression { - override fun toQueryString(): String = "*" -} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/SelectRawClause.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/SelectRawClause.kt index f9d4a01b..bf8f62db 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/SelectRawClause.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/SelectRawClause.kt @@ -1,9 +1,9 @@ package ch.ergon.dope.resolvable.clause.select import ch.ergon.dope.resolvable.clause.Clause -import ch.ergon.dope.resolvable.expression.Expression +import ch.ergon.dope.resolvable.expression.SingleExpression import ch.ergon.dope.resolvable.formatToQueryString -class SelectRawClause(private val expression: Expression) : Clause { +class SelectRawClause(private val expression: SingleExpression) : Clause { override fun toQueryString(): String = formatToQueryString("SELECT RAW", expression) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/factory/Select.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/factory/Select.kt index 44c19972..fce46335 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/factory/Select.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/clause/select/factory/Select.kt @@ -4,6 +4,7 @@ import ch.ergon.dope.resolvable.clause.Clause import ch.ergon.dope.resolvable.clause.ClauseBuilder import ch.ergon.dope.resolvable.clause.select.Fromable import ch.ergon.dope.resolvable.expression.Expression +import ch.ergon.dope.resolvable.expression.SingleExpression class Select(clauses: List = emptyList()) : From(clauses) { private val clauseBuilder: ClauseBuilder = @@ -11,11 +12,11 @@ class Select(clauses: List = emptyList()) : From(clauses) { fun select(expression: Expression, vararg expressions: Expression): From = clauseBuilder.select(expression, *expressions) - fun selectAll(): From = clauseBuilder.selectAll() + fun selectAsterisk(): From = clauseBuilder.selectAsterisk() fun selectDistinct(expression: Expression, vararg expressions: Expression): From = clauseBuilder.selectDistinct(expression, *expressions) - fun selectRaw(expression: Expression): From = clauseBuilder.selectRaw(expression) + fun selectRaw(expression: SingleExpression): From = clauseBuilder.selectRaw(expression) fun selectFrom(fromable: Fromable): Where = clauseBuilder.selectFrom(fromable) } diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/AsteriskExpression.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/AsteriskExpression.kt new file mode 100644 index 00000000..1249b692 --- /dev/null +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/AsteriskExpression.kt @@ -0,0 +1,24 @@ +package ch.ergon.dope.resolvable.expression + +import ch.ergon.dope.resolvable.fromable.AliasedBucket +import ch.ergon.dope.resolvable.fromable.Bucket +import ch.ergon.dope.resolvable.fromable.UnaliasedBucket + +const val ASTERISK_STRING = "*" + +class AsteriskExpression : Expression { + private val queryString: String + + constructor(bucket: Bucket) { + queryString = when (bucket) { + is AliasedBucket -> bucket.alias + is UnaliasedBucket -> bucket.name + } + ".$ASTERISK_STRING" + } + + constructor() { + queryString = ASTERISK_STRING + } + + override fun toQueryString(): String = queryString +} diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/Expression.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/Expression.kt index 13374148..96d38b75 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/Expression.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/Expression.kt @@ -5,6 +5,8 @@ import ch.ergon.dope.validtype.ValidType interface Expression : Resolvable -interface UnaliasedExpression : Expression +interface SingleExpression : Expression + +interface UnaliasedExpression : SingleExpression interface TypeExpression : UnaliasedExpression diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/aggregator/CountExpression.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/aggregator/CountExpression.kt index 0e93bd77..8026fd5c 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/aggregator/CountExpression.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/expression/unaliased/aggregator/CountExpression.kt @@ -1,8 +1,8 @@ package ch.ergon.dope.resolvable.expression.unaliased.aggregator +import ch.ergon.dope.resolvable.expression.ASTERISK_STRING import ch.ergon.dope.resolvable.expression.unaliased.type.Field import ch.ergon.dope.resolvable.formatToQueryStringWithBrackets -import ch.ergon.dope.validtype.StringType import ch.ergon.dope.validtype.ValidType class CountExpression( @@ -11,6 +11,10 @@ class CountExpression( override fun toQueryString(): String = formatToQueryStringWithBrackets("COUNT", field) } +class CountAsteriskExpression : AggregateExpression { + override fun toQueryString(): String = "COUNT($ASTERISK_STRING)" +} + fun count(field: Field) = CountExpression(field) -fun countAll() = CountExpression(Field("*", "")) +fun countAsterisk() = CountAsteriskExpression() diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/Bucket.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/Bucket.kt index 5f88a0fe..ea355142 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/Bucket.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/Bucket.kt @@ -1,8 +1,9 @@ package ch.ergon.dope.resolvable.fromable import ch.ergon.dope.resolvable.clause.select.Fromable +import ch.ergon.dope.resolvable.expression.AsteriskExpression -abstract class Bucket(open val name: String) : Fromable { +sealed class Bucket(open val name: String) : Fromable { override fun toQueryString(): String = name } @@ -13,3 +14,5 @@ open class UnaliasedBucket(name: String) : Bucket(name) { class AliasedBucket(name: String, val alias: String) : Bucket(name) { override fun toQueryString(): String = "$name AS $alias" } + +fun Bucket.asterisk() = AsteriskExpression(this) diff --git a/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/JoinOperator.kt b/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/JoinOperator.kt index 9f9862de..c1998caa 100644 --- a/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/JoinOperator.kt +++ b/core/src/main/kotlin/ch/ergon/dope/resolvable/fromable/JoinOperator.kt @@ -6,7 +6,7 @@ import ch.ergon.dope.resolvable.expression.unaliased.type.Field import ch.ergon.dope.validtype.BooleanType import ch.ergon.dope.validtype.ValidType -abstract class JoinOperator : Fromable { +sealed class JoinOperator : Fromable { private val queryString: String constructor(fromBucket: Bucket, joinType: String, goalBucket: Bucket, onCondition: TypeExpression) { diff --git a/core/src/test/kotlin/ch/ergon/dope/BooleanComparatorTest.kt b/core/src/test/kotlin/ch/ergon/dope/BooleanComparatorTest.kt index 19c2be30..6615438d 100644 --- a/core/src/test/kotlin/ch/ergon/dope/BooleanComparatorTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/BooleanComparatorTest.kt @@ -54,7 +54,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 2 > 4" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -69,7 +69,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 2 > 4" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -84,7 +84,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 2 > 4" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -112,7 +112,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" > \"test\"" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -127,7 +127,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" > \"test\"" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -142,7 +142,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" > \"test\"" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -197,7 +197,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 5 < 7" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -212,7 +212,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 5 < 7" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -227,7 +227,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 5 < 7" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -255,7 +255,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" < \"test\"" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -270,7 +270,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" < \"test\"" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -285,7 +285,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" < \"test\"" val actual = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -430,7 +430,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isNotEqualTo(5.toNumberType()), @@ -444,7 +444,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.isNotEqualTo(5), @@ -458,7 +458,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isNotEqualTo(5), @@ -472,7 +472,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.isNotEqualTo(5.toNumberType()), @@ -486,7 +486,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE numberField != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someNumberField().isNotEqualTo(5.toNumberType()), @@ -500,7 +500,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 3 != numberField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 3.toNumberType().isNotEqualTo(someNumberField()), @@ -514,7 +514,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"test\" != \"hallo\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isNotEqualTo("hallo".toStringType()), @@ -528,7 +528,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE stringField != \"5\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isNotEqualTo("5".toStringType()), @@ -542,7 +542,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 >= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isGreaterOrEqualThan(5.toNumberType()), @@ -556,7 +556,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 >= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.isGreaterOrEqualThan(5.toNumberType()), @@ -570,7 +570,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 >= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isGreaterOrEqualThan(5), @@ -584,7 +584,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"hallo\" >= \"test\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "hallo".isGreaterOrEqualThan("test".toStringType()), @@ -598,7 +598,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE stringField >= \"test\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isGreaterOrEqualThan("test"), @@ -612,7 +612,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE numberField >= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someNumberField().isGreaterOrEqualThan(5.toNumberType()), @@ -626,7 +626,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 3 >= numberField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 3.toNumberType().isGreaterOrEqualThan(someNumberField()), @@ -640,7 +640,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"test\" >= \"hallo\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isGreaterOrEqualThan("hallo".toStringType()), @@ -654,7 +654,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE stringField >= \"5\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isGreaterOrEqualThan("5".toStringType()), @@ -668,7 +668,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"test\" >= stringField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isGreaterOrEqualThan(someStringField()), @@ -682,7 +682,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 12 <= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isLessOrEqualThan(5.toNumberType()), @@ -696,7 +696,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE numberField <= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someNumberField().isLessOrEqualThan(5.toNumberType()), @@ -710,7 +710,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE 3 <= numberField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 3.toNumberType().isLessOrEqualThan(someNumberField()), @@ -724,7 +724,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE \"test\" <= \"hallo\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isLessOrEqualThan("hallo".toStringType()), @@ -738,7 +738,7 @@ class BooleanComparatorTest { val expected = "SELECT * FROM someBucket WHERE stringField <= \"5\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isLessOrEqualThan("5".toStringType()), diff --git a/core/src/test/kotlin/ch/ergon/dope/JoinOperatorTest.kt b/core/src/test/kotlin/ch/ergon/dope/JoinOperatorTest.kt index e1a365f5..769ba108 100644 --- a/core/src/test/kotlin/ch/ergon/dope/JoinOperatorTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/JoinOperatorTest.kt @@ -36,7 +36,7 @@ class JoinOperatorTest { val expected = "SELECT * FROM route JOIN airline ON route.airlineid = META(airline).id WHERE airline.country = \"France\"" val actual = create - .selectAll() + .selectAsterisk() .from( route.join( airline, @@ -58,7 +58,7 @@ class JoinOperatorTest { val expected = "SELECT * FROM route LEFT JOIN airline ON route.airlineid = META(airline).id WHERE route.sourceairport = \"SFO\"" val actual = create - .selectAll() + .selectAsterisk() .from( route.leftJoin( airline, @@ -78,7 +78,7 @@ class JoinOperatorTest { val expected = "SELECT * FROM route RIGHT JOIN airline ON route.airlineid = META(airline).id WHERE route.sourceairport = \"SFO\"" val actual = create - .selectAll() + .selectAsterisk() .from( route.rightJoin( airline, @@ -372,7 +372,7 @@ class JoinOperatorTest { val a = airline.alias("a") val actual = create - .selectAll() + .selectAsterisk() .from( r.join( a, @@ -392,7 +392,7 @@ class JoinOperatorTest { val r = someBucket("route").alias("r") val actual = create - .selectAll() + .selectAsterisk() .from( r.join( airline, diff --git a/core/src/test/kotlin/ch/ergon/dope/NumberFunctionsTest.kt b/core/src/test/kotlin/ch/ergon/dope/NumberFunctionsTest.kt index b7c50f39..041d8c2d 100644 --- a/core/src/test/kotlin/ch/ergon/dope/NumberFunctionsTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/NumberFunctionsTest.kt @@ -5,7 +5,7 @@ import ch.ergon.dope.helper.someNumberField import ch.ergon.dope.helper.someStringField import ch.ergon.dope.resolvable.expression.alias import ch.ergon.dope.resolvable.expression.unaliased.aggregator.count -import ch.ergon.dope.resolvable.expression.unaliased.aggregator.countAll +import ch.ergon.dope.resolvable.expression.unaliased.aggregator.countAsterisk import ch.ergon.dope.resolvable.expression.unaliased.aggregator.min import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType import junit.framework.TestCase.assertEquals @@ -56,7 +56,7 @@ class NumberFunctionsTest { val actual: String = create .select( - countAll(), + countAsterisk(), ).from( person, ).build() diff --git a/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt b/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt index 9535af4c..abaaffaa 100644 --- a/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/OrderByTest.kt @@ -20,7 +20,7 @@ class OrderByTest { val expected = "SELECT * FROM someBucket ORDER BY stringField" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).orderBy( @@ -35,7 +35,7 @@ class OrderByTest { val expected = "SELECT * FROM someBucket ORDER BY stringField ASC" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).orderBy( @@ -51,7 +51,7 @@ class OrderByTest { val expected = "SELECT * FROM someBucket ORDER BY stringField DESC" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).orderBy( diff --git a/core/src/test/kotlin/ch/ergon/dope/ParameterizedQueriesTest.kt b/core/src/test/kotlin/ch/ergon/dope/ParameterizedQueriesTest.kt index 15bf3ed9..d4cdbc9c 100644 --- a/core/src/test/kotlin/ch/ergon/dope/ParameterizedQueriesTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/ParameterizedQueriesTest.kt @@ -84,7 +84,7 @@ class ParameterizedQueriesTest { val expected = "SELECT *" val actual: String = - create.selectAll().build() + create.selectAsterisk().build() assertEquals(unifyString(expected), actual) } diff --git a/core/src/test/kotlin/ch/ergon/dope/QueryBuilderTest.kt b/core/src/test/kotlin/ch/ergon/dope/QueryBuilderTest.kt index 60c4e035..1c6761ff 100644 --- a/core/src/test/kotlin/ch/ergon/dope/QueryBuilderTest.kt +++ b/core/src/test/kotlin/ch/ergon/dope/QueryBuilderTest.kt @@ -22,6 +22,7 @@ import ch.ergon.dope.resolvable.expression.unaliased.type.stringfunction.nowStr import ch.ergon.dope.resolvable.expression.unaliased.type.toBooleanType import ch.ergon.dope.resolvable.expression.unaliased.type.toNumberType import ch.ergon.dope.resolvable.expression.unaliased.type.toStringType +import ch.ergon.dope.resolvable.fromable.asterisk import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals @@ -54,7 +55,7 @@ class QueryBuilderTest { val expected = "SELECT *\n" + " FROM someBucket\n" + " WHERE stringField = \"Ian\"\n" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -82,7 +83,7 @@ class QueryBuilderTest { val expected = "SELECT *\n" + " FROM someBucket\n" + " WHERE stringField = \"Ian\"\n" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -156,7 +157,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField < 50" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -171,7 +172,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField < 50 AND stringField = \"Mr.\"" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -188,7 +189,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField < 50 AND stringField = \"Mr.\"" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -209,7 +210,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE 12 != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isNotEqualTo(5.toNumberType()), @@ -223,7 +224,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField != 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someNumberField().isNotEqualTo(5.toNumberType()), @@ -237,7 +238,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE 3 != numberField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 3.toNumberType().isNotEqualTo(someNumberField()), @@ -251,7 +252,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE \"test\" != \"hallo\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isNotEqualTo("hallo".toStringType()), @@ -265,7 +266,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE stringField != \"5\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isNotEqualTo("5".toStringType()), @@ -279,7 +280,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE 12 >= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isGreaterOrEqualThan(5.toNumberType()), @@ -293,7 +294,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField >= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someNumberField().isGreaterOrEqualThan(5.toNumberType()), @@ -307,7 +308,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE 3 >= numberField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 3.toNumberType().isGreaterOrEqualThan(someNumberField()), @@ -321,7 +322,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE \"test\" >= \"hallo\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isGreaterOrEqualThan("hallo".toStringType()), @@ -335,7 +336,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE stringField >= \"5\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isGreaterOrEqualThan("5".toStringType()), @@ -349,7 +350,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE \"test\" >= stringField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isGreaterOrEqualThan(someStringField()), @@ -363,7 +364,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE 12 <= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 12.toNumberType().isLessOrEqualThan(5.toNumberType()), @@ -377,7 +378,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField <= 5" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someNumberField().isLessOrEqualThan(5.toNumberType()), @@ -391,7 +392,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE 3 <= numberField" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( 3.toNumberType().isLessOrEqualThan(someNumberField()), @@ -405,7 +406,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE \"test\" <= \"hallo\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( "test".toStringType().isLessOrEqualThan("hallo".toStringType()), @@ -419,7 +420,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE stringField <= \"5\"" val actual: String = create - .selectAll() + .selectAsterisk() .from(someBucket()) .where( someStringField().isLessOrEqualThan("5".toStringType()), @@ -433,7 +434,7 @@ class QueryBuilderTest { val expected = "SELECT * FROM someBucket WHERE numberField < 50 AND stringField = \"Mr.\" AND stringField = \"friend\"" val actual: String = create - .selectAll() + .selectAsterisk() .from( someBucket(), ).where( @@ -759,4 +760,30 @@ class QueryBuilderTest { assertEquals(expected, actual) } + + @Test + fun `should support selecting all Fields from bucket`() { + val someBucket = someBucket() + val expected = "SELECT someBucket.* FROM someBucket" + + val actual = create + .select(someBucket.asterisk()) + .from(someBucket) + .build() + + assertEquals(expected, actual) + } + + @Test + fun `should support selecting all Fields from aliased bucket`() { + val someBucket = someBucket().alias("alias") + val expected = "SELECT alias.* FROM someBucket AS alias" + + val actual = create + .select(someBucket.asterisk()) + .from(someBucket) + .build() + + assertEquals(expected, actual) + } } diff --git a/core/src/test/kotlin/ch/ergon/dope/helper/Builder.kt b/core/src/test/kotlin/ch/ergon/dope/helper/Builder.kt index 4a928d04..f13f8902 100644 --- a/core/src/test/kotlin/ch/ergon/dope/helper/Builder.kt +++ b/core/src/test/kotlin/ch/ergon/dope/helper/Builder.kt @@ -18,5 +18,5 @@ fun someBooleanField(name: String = "booleanField", bucket: Bucket = UnaliasedBu private fun getBucketName(bucket: Bucket): String = when (bucket) { is AliasedBucket -> bucket.alias - else -> bucket.name + is UnaliasedBucket -> bucket.name }