diff --git a/.scalafmt.conf b/.scalafmt.conf index 1d5a645010..ec325e1c1b 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,5 +1,5 @@ version = "3.7.17" -maxColumn = 120 +maxColumn = 240 align.preset = most align.multiline = false continuationIndent.defnSite = 2 @@ -7,13 +7,20 @@ assumeStandardLibraryStripMargin = true docstrings.style = Asterisk docstrings.wrapMaxColumn = 80 lineEndings = preserve -includeCurlyBraceInSelectChains = false danglingParentheses.preset = true optIn.annotationNewlines = true newlines.alwaysBeforeMultilineDef = false runner.dialect = scala213 rewrite.rules = [RedundantBraces] +# If I've inserted extra newlines I know what I'm doing, don't wrap them back. +newlines.source = keep + +# Don't change braces in one-liners to parens e.g. don't change this: `test("foo") { assertEquals(x,y) }` +# to this `test("foo")(assertEquals(x,y))`. The `rewrite.rules = [RedundantBraces]` will introduce this behavior +# unless you add the below option. +rewrite.redundantBraces.parensForOneLineApply = false + project.excludePaths = ["glob:**/scalafix/input/**", "glob:**/scalafix/output/**"] rewrite.redundantBraces.generalExpressions = false diff --git a/build/setup_db_scripts.sh b/build/setup_db_scripts.sh index 25c0b8e484..61ea4e5e51 100755 --- a/build/setup_db_scripts.sh +++ b/build/setup_db_scripts.sh @@ -34,6 +34,12 @@ function setup_sqlite() { DB_FILE=quill-jdbc-monix/quill_test.db rm -f $DB_FILE sqlite3 $DB_FILE < $SQLITE_SCRIPT + chmod a+rw $DB_FILE + + # DB File in quill-jdbc-monix + DB_FILE=quill-jdbc-test-sqlite/quill_test.db + rm -f $DB_FILE + sqlite3 $DB_FILE < $SQLITE_SCRIPT chmod a+rw $DB_FILE echo "Sqlite ready!" diff --git a/quill-cassandra-pekko/src/test/scala/io/getquill/context/cassandra/pekko/CassandraPekkoSpec.scala b/quill-cassandra-pekko/src/test/scala/io/getquill/context/cassandra/pekko/CassandraPekkoSpec.scala index 913c6790d3..772c3e481f 100644 --- a/quill-cassandra-pekko/src/test/scala/io/getquill/context/cassandra/pekko/CassandraPekkoSpec.scala +++ b/quill-cassandra-pekko/src/test/scala/io/getquill/context/cassandra/pekko/CassandraPekkoSpec.scala @@ -3,10 +3,7 @@ package io.getquill.context.cassandra.pekko import org.apache.pekko.actor.ActorSystem import org.apache.pekko.stream.Materializer import org.apache.pekko.stream.connectors.cassandra.CassandraSessionSettings -import org.apache.pekko.stream.connectors.cassandra.scaladsl.{ - CassandraSessionRegistry, - CassandraSession => CassandraPekkoSession -} +import org.apache.pekko.stream.connectors.cassandra.scaladsl.{CassandraSessionRegistry, CassandraSession => CassandraPekkoSession} import org.apache.pekko.testkit.TestKit import io.getquill.base.Spec import io.getquill.context.cassandra.CassandraTestEntities diff --git a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala index 365ee6aadb..811c386f94 100644 --- a/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala +++ b/quill-cassandra/src/main/scala/io/getquill/context/cassandra/encoding/CassandraTypes.scala @@ -1,14 +1,6 @@ package io.getquill.context.cassandra.encoding -import java.lang.{ - Boolean => JBoolean, - Byte => JByte, - Double => JDouble, - Float => JFloat, - Integer => JInt, - Long => JLong, - Short => JShort -} +import java.lang.{Boolean => JBoolean, Byte => JByte, Double => JDouble, Float => JFloat, Integer => JInt, Long => JLong, Short => JShort} import java.math.{BigDecimal => JBigDecimal} import java.nio.ByteBuffer import java.util.{Date, UUID} diff --git a/quill-core/src/test/scala/io/getquill/norm/FlattenOptionOperationSpec.scala b/quill-core/src/test/scala/io/getquill/norm/FlattenOptionOperationSpec.scala index 116b43cdd1..4cc67239cf 100644 --- a/quill-core/src/test/scala/io/getquill/norm/FlattenOptionOperationSpec.scala +++ b/quill-core/src/test/scala/io/getquill/norm/FlattenOptionOperationSpec.scala @@ -1,6 +1,6 @@ package io.getquill.norm -import io.getquill.ast._ +import io.getquill.ast.{+&&+, _} import io.getquill.MirrorContexts.testContext._ import io.getquill.ast.Implicits._ import io.getquill.norm.ConcatBehavior.{AnsiConcat, NonAnsiConcat} @@ -8,7 +8,7 @@ import io.getquill.MoreAstOps._ import io.getquill.base.Spec import io.getquill.util.TraceConfig -class FlattenOptionOperationSpec extends Spec { // hello +class FlattenOptionOperationSpec extends Spec { def o = Ident("o") def c1 = Constant.auto(1) @@ -156,7 +156,7 @@ class FlattenOptionOperationSpec extends Spec { // hello } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)( q.ast.body: Ast - ).toString mustEqual "((o != null) && (o < 1)) || ((o == null) && true)" + ).toString mustEqual "((o < 1) && (o != null)) || (true && (o == null))" } "map + getOrElse(false)" in { val q = quote { (o: Option[Int]) => @@ -164,7 +164,7 @@ class FlattenOptionOperationSpec extends Spec { // hello } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)( q.ast.body: Ast - ).toString mustEqual "((o != null) && (o < 1)) || ((o == null) && false)" + ).toString mustEqual "((o < 1) && (o != null)) || (false && (o == null))" } "forall" - { "regular operation" in { @@ -172,35 +172,35 @@ class FlattenOptionOperationSpec extends Spec { // hello o.forall(i => i != 1) } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNullCheck(o) +||+ (o +!=+ c1)) + ((o +!=+ c1) +||+ IsNullCheck(o)) new FlattenOptionOperation(NonAnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNullCheck(o) +||+ (o +!=+ c1)) + ((o +!=+ c1) +||+ IsNullCheck(o)) } "possible-fallthrough operation" in { val q = quote { (o: Option[String]) => o.forall(s => s + "foo" == "bar") } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNullCheck(o) +||+ ((o +++ cFoo) +==+ cBar)) + (((o +++ cFoo) +==+ cBar) +||+ IsNullCheck(o)) new FlattenOptionOperation(NonAnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNullCheck(o) +||+ (IsNotNullCheck(o) +&&+ ((o +++ cFoo) +==+ cBar))) + ((((o +++ cFoo) +==+ cBar) +&&+ IsNotNullCheck(o)) +||+ IsNullCheck(o)) } "never-fallthrough operation" in { val q = quote { (o: Option[String]) => o.forall(s => if (s + "foo" == "bar") true else false) } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNullCheck(o) +||+ (IsNotNullCheck(o) +&&+ If( + ((If( (o +++ cFoo) +==+ cBar, Constant.auto(true), Constant.auto(false) - ))) + ) +&&+ IsNotNullCheck(o)) +||+ IsNullCheck(o)) new FlattenOptionOperation(NonAnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNullCheck(o) +||+ (IsNotNullCheck(o) +&&+ If( + ((If( (o +++ cFoo) +==+ cBar, Constant.auto(true), Constant.auto(false) - ))) + ) +&&+ IsNotNullCheck(o)) +||+ IsNullCheck(o)) } } "map + forall + binop" - { @@ -209,19 +209,16 @@ class FlattenOptionOperationSpec extends Spec { // hello o.map(_.i).forall(i => i != 1) && true } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - ((IsNullCheck(Property(o, "i")) +||+ ((Property(o, "i") +!=+ c1))) +&&+ Constant.auto(true)) + ((((Property(o, "i") +!=+ c1)) +||+ IsNullCheck(Property(o, "i"))) +&&+ Constant.auto(true)) } "possible-fallthrough operation" in { val q = quote { (o: Option[TestEntity2]) => o.map(_.s).forall(s => s + "foo" == "bar") && true } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - ((IsNullCheck(Property(o, "s")) +||+ ((Property(o, "s") +++ cFoo) +==+ cBar) +&&+ Constant.auto(true))) + ((((Property(o, "s") +++ cFoo) +==+ cBar) +||+ IsNullCheck(Property(o, "s")) +&&+ Constant.auto(true))) new FlattenOptionOperation(NonAnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - ((IsNullCheck(Property(o, "s")) +||+ (IsNotNullCheck(Property(o, "s")) +&&+ ((Property( - o, - "s" - ) +++ cFoo) +==+ cBar))) +&&+ Constant.auto(true)) + (((((Property(o, "s") +++ cFoo) +==+ cBar) +&&+ IsNotNullCheck(Property(o, "s"))) +||+ IsNullCheck(Property(o, "s"))) +&&+ Constant.auto(true)) } } "exists" - { @@ -241,16 +238,16 @@ class FlattenOptionOperationSpec extends Spec { // hello new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual ((o +++ cFoo) +==+ cBar) new FlattenOptionOperation(NonAnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNotNullCheck(o) +&&+ ((o +++ cFoo) +==+ cBar)) + (((o +++ cFoo) +==+ cBar) +&&+ IsNotNullCheck(o)) } "never-fallthrough operation" in { val q = quote { (o: Option[String]) => o.exists(s => if (s + "foo" == "bar") true else false) } new FlattenOptionOperation(AnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNotNullCheck(o) +&&+ If((o +++ cFoo) +==+ cBar, Constant.auto(true), Constant.auto(false))) + (If((o +++ cFoo) +==+ cBar, Constant.auto(true), Constant.auto(false)) +&&+ IsNotNullCheck(o)) new FlattenOptionOperation(NonAnsiConcat, TraceConfig.Empty)(q.ast.body: Ast) mustEqual - (IsNotNullCheck(o) +&&+ If((o +++ cFoo) +==+ cBar, Constant.auto(true), Constant.auto(false))) + (If((o +++ cFoo) +==+ cBar, Constant.auto(true), Constant.auto(false)) +&&+ IsNotNullCheck(o)) } } "exists row" in { diff --git a/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala b/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala index ca9bd28242..f2c55d50c8 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/FlattenOptionOperation.scala @@ -34,11 +34,11 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC validateBody(body), () => { val reduction = BetaReduction(body, alias -> ast) - apply((IsNullCheck(ast) +||+ (IsNotNullCheck(ast) +&&+ reduction)): Ast) + apply(((reduction +&&+ IsNotNullCheck(ast)) +||+ IsNullCheck(ast)): Ast) }, () => { val reduced = BetaReduction(body, alias -> ast) - apply((IsNullCheck(ast) +||+ reduced): Ast) + apply((reduced +||+ IsNullCheck(ast)): Ast) } ) @@ -81,7 +81,7 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC case OptionGetOrElse(HasBooleanQuat(OptionMap(ast, alias, body)), HasBooleanQuat(alternative)) => val expr = BetaReduction(body, alias -> ast) - val output: Ast = (IsNotNullCheck(ast) +&&+ expr) +||+ (IsNullCheck(ast) +&&+ alternative) + val output: Ast = (expr +&&+ IsNotNullCheck(ast)) +||+ (alternative +&&+ IsNullCheck(ast)) apply(output) case OptionGetOrElse(ast, body) => @@ -96,6 +96,14 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC case OptionMap(ast, alias, body) => uncheckedReduction(ast, alias, body, containsNonFallthroughElement) + // a.orElse(b).forAll(alias => body) becomes: + // body(->a) || a==null && body(->b) || a==null && b==null + // + // Note that since all of the clauses are boolean this a.orElse(...) can be replaced + // by a||(b && a==null). If the clause was actually returning value (e.g. if(a) foo else bar) + // then these kinds of reductions would not be possible. + // Leaving the ||a==null clause without reversing for now despite the fact that ==null + // clauses shuold generally be the 2nd in the order because of the <> issue. case OptionForall(OptionOrElse(a, b), alias, body) => val reducedA = BetaReduction(body, alias -> a) val reducedB = BetaReduction(body, alias -> b) @@ -117,7 +125,7 @@ class FlattenOptionOperation(concatBehavior: ConcatBehavior, traceConfig: TraceC containsNonFallthroughElement(body), () => { val reduction = BetaReduction(body, alias -> ast) - apply(IsNotNullCheck(ast) +&&+ reduction: Ast) + apply(reduction +&&+ IsNotNullCheck(ast): Ast) }, () => apply(BetaReduction(body, alias -> ast)) ) diff --git a/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala b/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala index 89aaff0516..ac047a72e7 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/SheathLeafClauses.scala @@ -1,24 +1,6 @@ package io.getquill.norm -import io.getquill.ast.{ - Aggregation, - Ast, - CaseClass, - ConcatMap, - Distinct, - Filter, - FlatMap, - GroupBy, - GroupByMap, - Ident, - Join, - Map, - Property, - Query, - StatefulTransformerWithStack, - Union, - UnionAll -} +import io.getquill.ast.{Aggregation, Ast, CaseClass, ConcatMap, Distinct, Filter, FlatMap, GroupBy, GroupByMap, Ident, Join, Map, Property, Query, StatefulTransformerWithStack, Union, UnionAll} import io.getquill.ast.Ast.LeafQuat import io.getquill.ast.StatefulTransformerWithStack.History import io.getquill.util.{Interpolator, TraceConfig} diff --git a/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala b/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala index 5b9424ca36..0ce9cee323 100644 --- a/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala +++ b/quill-engine/src/main/scala/io/getquill/norm/capture/AvoidAliasConflict.scala @@ -1,19 +1,6 @@ package io.getquill.norm.capture -import io.getquill.ast.{ - Entity, - Filter, - FlatJoin, - FlatMap, - GroupBy, - Ident, - Join, - Map, - Query, - SortBy, - StatefulTransformer, - _ -} +import io.getquill.ast.{Entity, Filter, FlatJoin, FlatMap, GroupBy, Ident, Join, Map, Query, SortBy, StatefulTransformer, _} import io.getquill.ast.Implicits._ import io.getquill.norm.{BetaReduction, Normalize} import io.getquill.util.{Interpolator, TraceConfig} diff --git a/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala b/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala index bf5289f279..9f6d4af794 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/idiom/SqlIdiom.scala @@ -17,12 +17,7 @@ import io.getquill.norm.ConcatBehavior.AnsiConcat import io.getquill.norm.EqualityBehavior.AnsiEquality import io.getquill.norm.{ConcatBehavior, EqualityBehavior, ExpandReturning, NormalizeCaching, ProductAggregationToken} import io.getquill.quat.Quat -import io.getquill.sql.norm.{ - HideTopLevelFilterAlias, - NormalizeFilteredActionAliases, - RemoveExtraAlias, - RemoveUnusedSelects -} +import io.getquill.sql.norm.{HideTopLevelFilterAlias, NormalizeFilteredActionAliases, RemoveExtraAlias, RemoveUnusedSelects} import io.getquill.util.{Interleave, Interpolator, Messages, TraceConfig} import io.getquill.util.Messages.{TraceType, fail, trace} diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala index 7343895975..dcdb7adc25 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/RemoveUnusedSelects.scala @@ -1,20 +1,7 @@ package io.getquill.sql.norm import io.getquill.ast.{Ast, CollectAst, Ident, Property, StatefulTransformer} -import io.getquill.context.sql.{ - DistinctKind, - FlatJoinContext, - FlattenSqlQuery, - FromContext, - InfixContext, - JoinContext, - QueryContext, - SelectValue, - SetOperationSqlQuery, - SqlQuery, - TableContext, - UnaryOperationSqlQuery -} +import io.getquill.context.sql.{DistinctKind, FlatJoinContext, FlattenSqlQuery, FromContext, InfixContext, JoinContext, QueryContext, SelectValue, SetOperationSqlQuery, SqlQuery, TableContext, UnaryOperationSqlQuery} import io.getquill.norm.PropertyMatryoshka import io.getquill.quat.Quat diff --git a/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala b/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala index 588235c17e..205207c26a 100644 --- a/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala +++ b/quill-engine/src/main/scala/io/getquill/sql/norm/StatelessQueryTransformer.scala @@ -1,17 +1,6 @@ package io.getquill.sql.norm -import io.getquill.context.sql.{ - FlatJoinContext, - FlattenSqlQuery, - FromContext, - InfixContext, - JoinContext, - QueryContext, - SetOperationSqlQuery, - SqlQuery, - TableContext, - UnaryOperationSqlQuery -} +import io.getquill.context.sql.{FlatJoinContext, FlattenSqlQuery, FromContext, InfixContext, JoinContext, QueryContext, SetOperationSqlQuery, SqlQuery, TableContext, UnaryOperationSqlQuery} import io.getquill.quat.Quat sealed trait QueryLevel { diff --git a/quill-jdbc-test-sqlite/quill_test.db b/quill-jdbc-test-sqlite/quill_test.db deleted file mode 100644 index 89d70db507..0000000000 Binary files a/quill-jdbc-test-sqlite/quill_test.db and /dev/null differ diff --git a/quill-jdbc-zio/src/main/scala/io/getquill/ZioJdbcContexts.scala b/quill-jdbc-zio/src/main/scala/io/getquill/ZioJdbcContexts.scala index 13fefdef31..fa93615820 100644 --- a/quill-jdbc-zio/src/main/scala/io/getquill/ZioJdbcContexts.scala +++ b/quill-jdbc-zio/src/main/scala/io/getquill/ZioJdbcContexts.scala @@ -1,15 +1,7 @@ package io.getquill import com.typesafe.config.Config -import io.getquill.context.jdbc.{ - H2JdbcTypes, - MysqlJdbcTypes, - OracleJdbcTypes, - PostgresJdbcTypes, - SqlServerExecuteOverride, - SqlServerJdbcTypes, - SqliteJdbcTypes -} +import io.getquill.context.jdbc.{H2JdbcTypes, MysqlJdbcTypes, OracleJdbcTypes, PostgresJdbcTypes, SqlServerExecuteOverride, SqlServerJdbcTypes, SqliteJdbcTypes} import io.getquill.context.sql.idiom.SqlIdiom import io.getquill.context.json.PostgresJsonExtensions import io.getquill.context.qzio.{ZioJdbcContext, ZioJdbcUnderlyingContext} diff --git a/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala b/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala index 6b75db2a50..af47573162 100644 --- a/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala +++ b/quill-spark/src/main/scala/io/getquill/context/spark/SparkDialect.scala @@ -1,29 +1,9 @@ package io.getquill.context.spark import io.getquill.{IdiomContext, NamingStrategy} -import io.getquill.ast.{ - Ast, - BinaryOperation, - CaseClass, - Constant, - ExternalIdent, - Ident, - Operation, - Property, - Query, - StringOperator, - Tuple, - Value -} +import io.getquill.ast.{Ast, BinaryOperation, CaseClass, Constant, ExternalIdent, Ident, Operation, Property, Query, StringOperator, Tuple, Value} import io.getquill.context.spark.norm.EscapeQuestionMarks -import io.getquill.context.sql.{ - FlattenSqlQuery, - SelectValue, - SetOperationSqlQuery, - SqlQuery, - SqlQueryApply, - UnaryOperationSqlQuery -} +import io.getquill.context.sql.{FlattenSqlQuery, SelectValue, SetOperationSqlQuery, SqlQuery, SqlQueryApply, UnaryOperationSqlQuery} import io.getquill.context.sql.idiom.SqlIdiom import io.getquill.context.sql.norm.SqlNormalize import io.getquill.idiom.StatementInterpolator._ diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/EncodingSpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/EncodingSpec.scala index 8bdc3b3527..479ecdd4f8 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/EncodingSpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/EncodingSpec.scala @@ -3,17 +3,7 @@ package io.getquill.context.sql import io.getquill.base.Spec import java.time -import java.time.{ - Instant, - LocalDate, - LocalDateTime, - LocalTime, - OffsetDateTime, - OffsetTime, - ZoneId, - ZoneOffset, - ZonedDateTime -} +import java.time.{Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, ZoneId, ZoneOffset, ZonedDateTime} import java.util.{Date, UUID} case class EncodingTestType(value: String) diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/OptionSqlSpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/OptionSqlSpec.scala index a18b3e4665..6c6f42a161 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/OptionSqlSpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/OptionSqlSpec.scala @@ -12,7 +12,7 @@ class OptionSqlSpec extends Spec { testContext.run { query[Someone].filter(s => s.name.forall(n => n == "Joe")) }.string mustEqual - "SELECT s.name FROM Someone s WHERE s.name IS NULL OR s.name = 'Joe'" + "SELECT s.name FROM Someone s WHERE s.name = 'Joe' OR s.name IS NULL" } "exists" in { testContext.run { @@ -71,11 +71,11 @@ class OptionSqlSpec extends Spec { "normally" in { val q = quote(query[Node].map(s => s.isUp.map(n => n == true).getOrElse(false))) testContext.run(q).string mustEqual - "SELECT s.isUp IS NOT NULL AND s.isUp = true OR s.isUp IS NULL AND false FROM Node s" + "SELECT s.isUp = true AND s.isUp IS NOT NULL OR false AND s.isUp IS NULL FROM Node s" } "map to self" in { testContext.run(query[Node].map(s => s.isUp.map(n => n).getOrElse(false))).string mustEqual - "SELECT s.isUp IS NOT NULL AND s.isUp OR s.isUp IS NULL AND false FROM Node s" + "SELECT s.isUp AND s.isUp IS NOT NULL OR false AND s.isUp IS NULL FROM Node s" } "simple" in { testContext.run(query[Node].map(s => s.isUp.getOrElse(false))).string mustEqual @@ -85,11 +85,11 @@ class OptionSqlSpec extends Spec { "in filter clause" - { "normally" in { testContext.run(query[Node].filter(s => s.isUp.map(n => n == true).getOrElse(false))).string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND s.isUp = true OR s.isUp IS NULL AND false" + "SELECT s.name, s.isUp FROM Node s WHERE s.isUp = true AND s.isUp IS NOT NULL OR false AND s.isUp IS NULL" } "map to self" in { testContext.run(query[Node].filter(s => s.isUp.map(n => n).getOrElse(false))).string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND s.isUp OR s.isUp IS NULL AND false" + "SELECT s.name, s.isUp FROM Node s WHERE s.isUp AND s.isUp IS NOT NULL OR false AND s.isUp IS NULL" } "simple" in { testContext.run(query[Node].filter(s => s.isUp.getOrElse(false))).string mustEqual @@ -102,12 +102,12 @@ class OptionSqlSpec extends Spec { "normally" in { testContext.run { query[Node].map(s => s.isUp.map(n => n == true).getOrElse(lift(false))) - }.string mustEqual // hello - "SELECT s.isUp IS NOT NULL AND s.isUp = true OR s.isUp IS NULL AND ? FROM Node s" + }.string mustEqual + "SELECT s.isUp = true AND s.isUp IS NOT NULL OR ? AND s.isUp IS NULL FROM Node s" } "map to self" in { testContext.run(query[Node].map(s => s.isUp.map(n => n).getOrElse(lift(false)))).string mustEqual - "SELECT s.isUp IS NOT NULL AND s.isUp OR s.isUp IS NULL AND ? FROM Node s" + "SELECT s.isUp AND s.isUp IS NOT NULL OR ? AND s.isUp IS NULL FROM Node s" } "simple" in { testContext.run(query[Node].map(s => s.isUp.getOrElse(lift(false)))).string mustEqual @@ -118,12 +118,12 @@ class OptionSqlSpec extends Spec { "normally" in { testContext.run { query[Node].filter(s => s.isUp.map(n => n == true).getOrElse(lift(false))) - }.string mustEqual // hello - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND s.isUp = true OR s.isUp IS NULL AND ?" + }.string mustEqual + "SELECT s.name, s.isUp FROM Node s WHERE s.isUp = true AND s.isUp IS NOT NULL OR ? AND s.isUp IS NULL" } "map to self" in { testContext.run(query[Node].filter(s => s.isUp.map(n => n).getOrElse(lift(false)))).string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND s.isUp OR s.isUp IS NULL AND ?" + "SELECT s.name, s.isUp FROM Node s WHERE s.isUp AND s.isUp IS NOT NULL OR ? AND s.isUp IS NULL" } "simple" in { testContext.run(query[Node].filter(s => s.isUp.getOrElse(lift(false)))).string mustEqual @@ -143,13 +143,13 @@ class OptionSqlSpec extends Spec { testContext.run { query[Node].map(s => s.isUp.map(n => n == true).getOrElse(false)) }.string mustEqual - "SELECT CASE WHEN s.isUp IS NOT NULL AND s.isUp = 1 OR s.isUp IS NULL AND 1 = 0 THEN 1 ELSE 0 END FROM Node s" + "SELECT CASE WHEN s.isUp = 1 AND s.isUp IS NOT NULL OR 1 = 0 AND s.isUp IS NULL THEN 1 ELSE 0 END FROM Node s" } "map to self" in { testContext.run { query[Node].map(s => s.isUp.map(n => n).getOrElse(false)) }.string mustEqual - "SELECT CASE WHEN s.isUp IS NOT NULL AND 1 = s.isUp OR s.isUp IS NULL AND 1 = 0 THEN 1 ELSE 0 END FROM Node s" + "SELECT CASE WHEN 1 = s.isUp AND s.isUp IS NOT NULL OR 1 = 0 AND s.isUp IS NULL THEN 1 ELSE 0 END FROM Node s" } "simple" in { testContext.run { @@ -163,13 +163,13 @@ class OptionSqlSpec extends Spec { testContext.run { query[Node].filter(s => s.isUp.map(n => n == true).getOrElse(false)) }.string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND s.isUp = 1 OR s.isUp IS NULL AND 1 = 0" + "SELECT s.name, s.isUp FROM Node s WHERE s.isUp = 1 AND s.isUp IS NOT NULL OR 1 = 0 AND s.isUp IS NULL" } "map to self" in { testContext.run { query[Node].filter(s => s.isUp.map(n => n).getOrElse(false)) }.string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND 1 = s.isUp OR s.isUp IS NULL AND 1 = 0" + "SELECT s.name, s.isUp FROM Node s WHERE 1 = s.isUp AND s.isUp IS NOT NULL OR 1 = 0 AND s.isUp IS NULL" } "simple" in { val q = quote(query[Node].filter(s => s.isUp.getOrElse(false))) @@ -184,13 +184,13 @@ class OptionSqlSpec extends Spec { testContext.run { query[Node].map(s => s.isUp.map(n => n == true).getOrElse(lift(false))) }.string mustEqual - "SELECT CASE WHEN s.isUp IS NOT NULL AND s.isUp = 1 OR s.isUp IS NULL AND 1 = ? THEN 1 ELSE 0 END FROM Node s" + "SELECT CASE WHEN s.isUp = 1 AND s.isUp IS NOT NULL OR 1 = ? AND s.isUp IS NULL THEN 1 ELSE 0 END FROM Node s" } "map to self" in { testContext.run { query[Node].map(s => s.isUp.map(n => n).getOrElse(lift(false))) }.string mustEqual - "SELECT CASE WHEN s.isUp IS NOT NULL AND 1 = s.isUp OR s.isUp IS NULL AND 1 = ? THEN 1 ELSE 0 END FROM Node s" + "SELECT CASE WHEN 1 = s.isUp AND s.isUp IS NOT NULL OR 1 = ? AND s.isUp IS NULL THEN 1 ELSE 0 END FROM Node s" } "simple" in { testContext.run { @@ -204,13 +204,13 @@ class OptionSqlSpec extends Spec { testContext.run { query[Node].filter(s => s.isUp.map(n => n == true).getOrElse(lift(false))) }.string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND s.isUp = 1 OR s.isUp IS NULL AND 1 = ?" + "SELECT s.name, s.isUp FROM Node s WHERE s.isUp = 1 AND s.isUp IS NOT NULL OR 1 = ? AND s.isUp IS NULL" } "map to self" in { testContext.run { query[Node].filter(s => s.isUp.map(n => n).getOrElse(lift(false))) }.string mustEqual - "SELECT s.name, s.isUp FROM Node s WHERE s.isUp IS NOT NULL AND 1 = s.isUp OR s.isUp IS NULL AND 1 = ?" + "SELECT s.name, s.isUp FROM Node s WHERE 1 = s.isUp AND s.isUp IS NOT NULL OR 1 = ? AND s.isUp IS NULL" } "simple" in { testContext.run { diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/SqlQuerySpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/SqlQuerySpec.scala index 114f2e436a..dc9d4fc7e8 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/SqlQuerySpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/SqlQuerySpec.scala @@ -47,7 +47,7 @@ class SqlQuerySpec extends Spec { .filter(_._2.forall(_ == 1)) } testContext.run(q).string mustEqual - "SELECT a.i AS _1, b.i AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i IS NULL OR b.i = 1" + "SELECT a.i AS _1, b.i AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i = 1 OR b.i IS NULL" } "null-checked" in { val q = quote { @@ -58,7 +58,7 @@ class SqlQuerySpec extends Spec { .filter(_._2.forall(v => if (v == "value") true else false)) } testContext.run(q).string mustEqual - "SELECT a.i AS _1, b.s AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.s IS NULL OR b.s IS NOT NULL AND CASE WHEN b.s = 'value' THEN true ELSE false END" + "SELECT a.i AS _1, b.s AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE CASE WHEN b.s = 'value' THEN true ELSE false END AND b.s IS NOT NULL OR b.s IS NULL" } } diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/BooleanLiteralSupportSpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/BooleanLiteralSupportSpec.scala index 68eb8b0a0f..54d639c7c2 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/BooleanLiteralSupportSpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/BooleanLiteralSupportSpec.scala @@ -206,7 +206,7 @@ class BooleanLiteralSupportSpec extends Spec { qr1.filter(t => t.o.exists(_ => if (false) false else true)).map(t => (t.b, true)) } ctx.run(q).string mustEqual - "SELECT t.b AS _1, 1 AS _2 FROM TestEntity t WHERE t.o IS NOT NULL AND (1 = 0 AND 1 = 0 OR NOT (1 = 0) AND 1 = 1)" + "SELECT t.b AS _1, 1 AS _2 FROM TestEntity t WHERE (1 = 0 AND 1 = 0 OR NOT (1 = 0) AND 1 = 1) AND t.o IS NOT NULL" } "exists - lifted" in testContext.withDialect(MirrorSqlDialectWithBooleanLiterals) { ctx => @@ -215,7 +215,7 @@ class BooleanLiteralSupportSpec extends Spec { qr1.filter(t => t.o.exists(_ => if (lift(false)) lift(false) else lift(true))).map(t => (t.b, true)) } ctx.run(q).string mustEqual - "SELECT t.b AS _1, 1 AS _2 FROM TestEntity t WHERE t.o IS NOT NULL AND (1 = ? AND 1 = ? OR NOT (1 = ?) AND 1 = ?)" + "SELECT t.b AS _1, 1 AS _2 FROM TestEntity t WHERE (1 = ? AND 1 = ? OR NOT (1 = ?) AND 1 = ?) AND t.o IS NOT NULL" } } @@ -272,7 +272,7 @@ class BooleanLiteralSupportSpec extends Spec { .filter(_._2.forall(v => if (true) true else false)) } ctx.run(q).string mustEqual - "SELECT a.i AS _1, b.s AS _2, 0 AS _3 FROM TestEntity a LEFT JOIN TestEntity2 b ON 1 = 0 WHERE b.s IS NULL OR b.s IS NOT NULL AND (1 = 1 AND 1 = 1 OR NOT (1 = 1) AND 1 = 0)" + "SELECT a.i AS _1, b.s AS _2, 0 AS _3 FROM TestEntity a LEFT JOIN TestEntity2 b ON 1 = 0 WHERE (1 = 1 AND 1 = 1 OR NOT (1 = 1) AND 1 = 0) AND b.s IS NOT NULL OR b.s IS NULL" } "join + map + filter (lifted)" in testContext.withDialect(MirrorSqlDialectWithBooleanLiterals) { ctx => @@ -285,7 +285,7 @@ class BooleanLiteralSupportSpec extends Spec { .filter(_._2.forall(v => if (lift(true)) lift(true) else lift(false))) } ctx.run(q).string mustEqual - "SELECT a.i AS _1, b.s AS _2, 0 AS _3 FROM TestEntity a LEFT JOIN TestEntity2 b ON 1 = 0 WHERE b.s IS NULL OR b.s IS NOT NULL AND (1 = ? AND 1 = ? OR NOT (1 = ?) AND 1 = ?)" + "SELECT a.i AS _1, b.s AS _2, 0 AS _3 FROM TestEntity a LEFT JOIN TestEntity2 b ON 1 = 0 WHERE (1 = ? AND 1 = ? OR NOT (1 = ?) AND 1 = ?) AND b.s IS NOT NULL OR b.s IS NULL" } "for-comprehension with constant" in testContext.withDialect(MirrorSqlDialectWithBooleanLiterals) { ctx => diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomOptionCompareSpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomOptionCompareSpec.scala index 450f4f0174..380baf6fd4 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomOptionCompareSpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomOptionCompareSpec.scala @@ -107,35 +107,35 @@ class SqlIdiomOptionCompareSpec extends Spec { qr1.filter(t => t.o.exists(op => if (op != 1) false else true)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.o IS NOT NULL AND CASE WHEN t.o <> 1 THEN false ELSE true END" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE CASE WHEN t.o <> 1 THEN false ELSE true END AND t.o IS NOT NULL" } "forall" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.forall(op => op == 1)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o = 1)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o = 1 OR t.o IS NULL)" } "forall with null-check" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.forall(op => if (op != 1) false else true)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o IS NOT NULL AND CASE WHEN t.o <> 1 THEN false ELSE true END)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (CASE WHEN t.o <> 1 THEN false ELSE true END AND t.o IS NOT NULL OR t.o IS NULL)" } "filterIfDefined" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.filterIfDefined(op => op == 1)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o = 1)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o = 1 OR t.o IS NULL)" } "filterIfDefined with null-check" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.filterIfDefined(op => if (op != 1) false else true)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o IS NOT NULL AND CASE WHEN t.o <> 1 THEN false ELSE true END)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (CASE WHEN t.o <> 1 THEN false ELSE true END AND t.o IS NOT NULL OR t.o IS NULL)" } "embedded" - { case class TestEntity(optionalEmbedded: Option[EmbeddedEntity]) @@ -184,7 +184,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NOT NULL AND CASE WHEN t.optionalValue = 1 THEN true ELSE false END" + "SELECT t.optionalValue FROM TestEntity t WHERE CASE WHEN t.optionalValue = 1 THEN true ELSE false END AND t.optionalValue IS NOT NULL" } "forall" in { val q = quote { @@ -192,7 +192,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue = 1" + "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue = 1 OR t.optionalValue IS NULL" } "forall with null-check" in { val q = quote { @@ -202,7 +202,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue IS NOT NULL AND CASE WHEN t.optionalValue = 1 THEN true ELSE false END" + "SELECT t.optionalValue FROM TestEntity t WHERE CASE WHEN t.optionalValue = 1 THEN true ELSE false END AND t.optionalValue IS NOT NULL OR t.optionalValue IS NULL" } "filterIfDefined" in { val q = quote { @@ -210,7 +210,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue = 1" + "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue = 1 OR t.optionalValue IS NULL" } "filterIfDefined with null-check" in { val q = quote { @@ -220,7 +220,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue IS NOT NULL AND CASE WHEN t.optionalValue = 1 THEN true ELSE false END" + "SELECT t.optionalValue FROM TestEntity t WHERE CASE WHEN t.optionalValue = 1 THEN true ELSE false END AND t.optionalValue IS NOT NULL OR t.optionalValue IS NULL" } } } @@ -323,35 +323,35 @@ class SqlIdiomOptionCompareSpec extends Spec { qr1.filter(t => t.o.exists(op => if (op != 1) false else true)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.o IS NOT NULL AND CASE WHEN t.o <> 1 THEN false ELSE true END" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE CASE WHEN t.o <> 1 THEN false ELSE true END AND t.o IS NOT NULL" } "forall" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.forall(op => op == 1)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o = 1)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o = 1 OR t.o IS NULL)" } "forall with null-check" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.forall(op => if (op != 1) false else true)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o IS NOT NULL AND CASE WHEN t.o <> 1 THEN false ELSE true END)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (CASE WHEN t.o <> 1 THEN false ELSE true END AND t.o IS NOT NULL OR t.o IS NULL)" } "filterIfDefined" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.filterIfDefined(op => op == 1)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o = 1)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o = 1 OR t.o IS NULL)" } "filterIfDefined with null-check" in { val q = quote { qr1.filter(t => t.i != 1 && t.o.filterIfDefined(op => if (op != 1) false else true)) } testContext.run(q).string mustEqual - "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (t.o IS NULL OR t.o IS NOT NULL AND CASE WHEN t.o <> 1 THEN false ELSE true END)" + "SELECT t.s, t.i, t.l, t.o, t.b FROM TestEntity t WHERE t.i <> 1 AND (CASE WHEN t.o <> 1 THEN false ELSE true END AND t.o IS NOT NULL OR t.o IS NULL)" } "embedded" - { case class TestEntity(optionalEmbedded: Option[EmbeddedEntity]) @@ -400,7 +400,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NOT NULL AND CASE WHEN t.optionalValue = 1 THEN true ELSE false END" + "SELECT t.optionalValue FROM TestEntity t WHERE CASE WHEN t.optionalValue = 1 THEN true ELSE false END AND t.optionalValue IS NOT NULL" } "forall" in { val q = quote { @@ -408,7 +408,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue = 1" + "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue = 1 OR t.optionalValue IS NULL" } "forall with null-check" in { val q = quote { @@ -418,7 +418,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue IS NOT NULL AND CASE WHEN t.optionalValue = 1 THEN true ELSE false END" + "SELECT t.optionalValue FROM TestEntity t WHERE CASE WHEN t.optionalValue = 1 THEN true ELSE false END AND t.optionalValue IS NOT NULL OR t.optionalValue IS NULL" } "filterIfDefined" in { val q = quote { @@ -426,7 +426,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue = 1" + "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue = 1 OR t.optionalValue IS NULL" } "filterIfDefined with null-check" in { val q = quote { @@ -436,7 +436,7 @@ class SqlIdiomOptionCompareSpec extends Spec { } testContext.run(q).string mustEqual - "SELECT t.optionalValue FROM TestEntity t WHERE t.optionalValue IS NULL OR t.optionalValue IS NOT NULL AND CASE WHEN t.optionalValue = 1 THEN true ELSE false END" + "SELECT t.optionalValue FROM TestEntity t WHERE CASE WHEN t.optionalValue = 1 THEN true ELSE false END AND t.optionalValue IS NOT NULL OR t.optionalValue IS NULL" } } } diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomSpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomSpec.scala index 3e0c2a5935..4cce884d8c 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomSpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/SqlIdiomSpec.scala @@ -913,14 +913,14 @@ class SqlIdiomSpec extends Spec { qr1.filter(t => t.o.map(_ < 10).getOrElse(true)).map(t => t.i) } testContext.run(q).string mustEqual - "SELECT t.i FROM TestEntity t WHERE t.o IS NOT NULL AND t.o < 10 OR t.o IS NULL AND true" + "SELECT t.i FROM TestEntity t WHERE t.o < 10 AND t.o IS NOT NULL OR true AND t.o IS NULL" } "is not null" in { val q = quote { qr1.filter(t => t.o.map(_ < 10).getOrElse(false)).map(t => t.i) } testContext.run(q).string mustEqual - "SELECT t.i FROM TestEntity t WHERE t.o IS NOT NULL AND t.o < 10 OR t.o IS NULL AND false" + "SELECT t.i FROM TestEntity t WHERE t.o < 10 AND t.o IS NOT NULL OR false AND t.o IS NULL" } } } diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/test b/quill-sql-test/src/test/scala/io/getquill/context/sql/idiom/test new file mode 100644 index 0000000000..e69de29bb2 diff --git a/quill-sql-test/src/test/scala/io/getquill/context/sql/norm/JoinSpec.scala b/quill-sql-test/src/test/scala/io/getquill/context/sql/norm/JoinSpec.scala index 4a6e00827a..1678367d1d 100644 --- a/quill-sql-test/src/test/scala/io/getquill/context/sql/norm/JoinSpec.scala +++ b/quill-sql-test/src/test/scala/io/getquill/context/sql/norm/JoinSpec.scala @@ -15,7 +15,7 @@ class JoinSpec extends Spec { .filter(_._2.map(_.i).forall(_ == 1)) } testContext.run(q).string mustEqual - "SELECT a.s, a.i, a.l, a.o, a.b, b.s, b.i, b.l, b.o FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i IS NULL OR b.i = 1" + "SELECT a.s, a.i, a.l, a.o, a.b, b.s, b.i, b.l, b.o FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i = 1 OR b.i IS NULL" } "join + filter with null-check" in { @@ -26,7 +26,7 @@ class JoinSpec extends Spec { .filter(_._2.map(_.i).forall(b => if (b == 1) true else false)) } testContext.run(q).string mustEqual - "SELECT a.s, a.i, a.l, a.o, a.b, b.s, b.i, b.l, b.o FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i IS NULL OR b.i IS NOT NULL AND CASE WHEN b.i = 1 THEN true ELSE false END" + "SELECT a.s, a.i, a.l, a.o, a.b, b.s, b.i, b.l, b.o FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE CASE WHEN b.i = 1 THEN true ELSE false END AND b.i IS NOT NULL OR b.i IS NULL" } "join + map + filter" in { @@ -38,7 +38,7 @@ class JoinSpec extends Spec { .filter(_._2.forall(_ == 1)) } testContext.run(q).string mustEqual - "SELECT a.i AS _1, b.i AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i IS NULL OR b.i = 1" + "SELECT a.i AS _1, b.i AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i = 1 OR b.i IS NULL" } "join + map + filter with null-check" in { @@ -50,7 +50,7 @@ class JoinSpec extends Spec { .filter(_._2.forall(b => if (b == 1) true else false)) } testContext.run(q).string mustEqual - "SELECT a.i AS _1, b.i AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE b.i IS NULL OR b.i IS NOT NULL AND CASE WHEN b.i = 1 THEN true ELSE false END" + "SELECT a.i AS _1, b.i AS _2 FROM TestEntity a LEFT JOIN TestEntity2 b ON a.i = b.i WHERE CASE WHEN b.i = 1 THEN true ELSE false END AND b.i IS NOT NULL OR b.i IS NULL" } "join + filter + leftjoin" in { diff --git a/quill-test-kit/src/test/scala/io/getquill/context/sql/EncodingSpec.scala b/quill-test-kit/src/test/scala/io/getquill/context/sql/EncodingSpec.scala index 8bdc3b3527..479ecdd4f8 100644 --- a/quill-test-kit/src/test/scala/io/getquill/context/sql/EncodingSpec.scala +++ b/quill-test-kit/src/test/scala/io/getquill/context/sql/EncodingSpec.scala @@ -3,17 +3,7 @@ package io.getquill.context.sql import io.getquill.base.Spec import java.time -import java.time.{ - Instant, - LocalDate, - LocalDateTime, - LocalTime, - OffsetDateTime, - OffsetTime, - ZoneId, - ZoneOffset, - ZonedDateTime -} +import java.time.{Instant, LocalDate, LocalDateTime, LocalTime, OffsetDateTime, OffsetTime, ZoneId, ZoneOffset, ZonedDateTime} import java.util.{Date, UUID} case class EncodingTestType(value: String)