From e3b8e6ce8f659bff81b9a4bc3a79e3d2c3dd734f Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Mon, 23 Oct 2017 15:34:13 +0700 Subject: Removed quill query builder --- .../scala/xyz/driver/pdsuicommon/BaseSuite.scala | 12 - src/test/scala/xyz/driver/pdsuicommon/Mocks.scala | 51 +--- .../BridgeUploadQueueRepositoryAdapterSuite.scala | 285 ------------------- .../db/QueryBuilderParametersSuite.scala | 310 --------------------- 4 files changed, 12 insertions(+), 646 deletions(-) delete mode 100644 src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala delete mode 100644 src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala (limited to 'src/test/scala/xyz/driver/pdsuicommon') diff --git a/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala index 7c9d8c4..29e7610 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/BaseSuite.scala @@ -5,15 +5,12 @@ import java.time.{LocalDateTime, ZoneId} import org.scalatest.FreeSpecLike import org.scalatest.concurrent.ScalaFutures import org.scalatest.time.{Millis, Span} -import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.domain._ -import xyz.driver.pdsuicommon.error.UnexpectedFilterException import xyz.driver.pdsuicommon.utils.DiffUtils trait BaseSuite extends FreeSpecLike with DiffUtils with ScalaFutures { implicit val defaultPatience = PatienceConfig(timeout = Span(1000, Millis), interval = Span(20, Millis)) - implicit val sqlContext = new MockMySqlContext() def sampleUser(role: User.Role, email: String = "test@example.com", password: String = "123") = User( id = StringId("2001"), @@ -23,13 +20,4 @@ trait BaseSuite extends FreeSpecLike with DiffUtils with ScalaFutures { latestActivity = Some(LocalDateTime.now(ZoneId.of("Z"))), deleted = None ) - - def createMockQueryBuilder[T](isExpectedFilter: SearchFilterExpr => Boolean): MysqlQueryBuilder[T] = { - MockQueryBuilder[T] { - case (filter, _, _) if isExpectedFilter(filter) => Seq.empty - case (filter, _, _) => throw new UnexpectedFilterException(s"Filter is unexpected: $filter") - } { - case _ => (0, Option.empty[LocalDateTime]) - } - } } diff --git a/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala b/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala index 51d39e5..699020c 100644 --- a/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala +++ b/src/test/scala/xyz/driver/pdsuicommon/Mocks.scala @@ -6,7 +6,7 @@ import java.sql.Connection import java.util.logging.Logger import javax.sql.DataSource -import com.typesafe.config.ConfigFactory +import xyz.driver.pdsuicommon.db.SlickQueryBuilder.TableData import xyz.driver.pdsuicommon.db._ import xyz.driver.pdsuicommon.http.HttpFetcher @@ -27,32 +27,7 @@ class MockDataSource extends DataSource with Closeable { override def isWrapperFor(iface: Class[_]): Boolean = throw new NotImplementedError("MockDataSource.isWrapperFor") } -object MockMySqlContext { - - val Settings = MySqlContext.Settings( - credentials = MySqlContext.DbCredentials( - user = "test", - password = "test", - host = "localhost", - port = 3248, - dbName = "test", - dbCreateFlag = false, - dbContext = "test", - connectionParams = "", - url = "" - ), - connection = ConfigFactory.empty(), - threadPoolSize = 10 - ) -} - -class MockMySqlContext() extends MySqlContext(new MockDataSource, MockMySqlContext.Settings) { - override protected def withConnection[T](f: Connection => T): Nothing = { - throw new NotImplementedError("MockSqlContext.withConnection") - } -} - -class MockFactory()(implicit val sqlContext: MySqlContext) { +class MockFactory()(implicit val sqlContext: PostgresContext) { val MockHttpFetcher: HttpFetcher = { (url: URL) => Future.successful(Array.empty[Byte]) } @@ -61,28 +36,26 @@ class MockFactory()(implicit val sqlContext: MySqlContext) { object MockQueryBuilder { type MockRunnerIn = (SearchFilterExpr, Sorting, Option[Pagination]) - type MockRunnerOut[T] = Seq[T] - type MockCountRunnerOut = QueryBuilder.CountResult + type MockRunnerOut[T] = Future[Seq[T]] + type MockCountRunnerOut = SlickQueryBuilder.CountResult def apply[T](matcher: PartialFunction[MockRunnerIn, MockRunnerOut[T]])( countMatcher: PartialFunction[MockRunnerIn, MockCountRunnerOut])( - implicit context: MySqlContext): MysqlQueryBuilder[T] = { + implicit context: PostgresContext): SlickQueryBuilder[T] = { - val runner: QueryBuilder.Runner[T] = { parameters => + val runner: SlickQueryBuilder.Runner[T] = { parameters => matcher((parameters.filter, parameters.sorting, parameters.pagination)) } - val countRunner: QueryBuilder.CountRunner = { parameters => + val countRunner: SlickQueryBuilder.CountRunner = { parameters => countMatcher((parameters.filter, parameters.sorting, parameters.pagination)) } - MysqlQueryBuilder[T]( - tableName = "", - lastUpdateFieldName = Option.empty[String], - nullableFields = Set.empty[String], - links = Set.empty[TableLink], - runner = runner, - countRunner = countRunner + val parameters = SlickPostgresQueryBuilderParameters( + databaseName = "test", + tableData = TableData("", None, Set.empty[String]), + links = Map.empty ) + new SlickPostgresQueryBuilder(parameters)(runner, countRunner) } } diff --git a/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala deleted file mode 100644 index 8b38316..0000000 --- a/src/test/scala/xyz/driver/pdsuicommon/concurrent/BridgeUploadQueueRepositoryAdapterSuite.scala +++ /dev/null @@ -1,285 +0,0 @@ -package xyz.driver.pdsuicommon.concurrent - -import java.util.concurrent.ThreadLocalRandom - -import xyz.driver.pdsuicommon.BaseSuite -import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueueRepositoryAdapter.Strategy -import xyz.driver.pdsuicommon.concurrent.BridgeUploadQueueRepositoryAdapter.Strategy.{OnAttempt, OnComplete} -import xyz.driver.pdsuicommon.db.{FakeDbIo, MysqlQueryBuilder} -import xyz.driver.pdsuicommon.db.repositories.BridgeUploadQueueRepository - -import scala.concurrent.Future -import scala.concurrent.duration.DurationInt - -class BridgeUploadQueueRepositoryAdapterSuite extends BaseSuite { - - // IDEA have some issue here with imports - private implicit val executionContext = scala.concurrent.ExecutionContext.global - - "Strategy" - { - "LimitExponential" - { - "on" - { - val strategy = Strategy.LimitExponential( - startInterval = 10.seconds, - intervalFactor = 1.4, - maxInterval = 50.seconds, - onComplete = OnComplete.Delete - ) - - "a new interval should be greater than the previous one if the limit not reached" in { - val previous = strategy.on(1) - val current = strategy.on(2) - - (previous, current) match { - case (OnAttempt.Continue(a), OnAttempt.Continue(b)) => assert(a < b) - case x => fail(s"Unexpected result: $x") - } - } - - "should limit intervals" in { - assert(strategy.on(20) == OnAttempt.Continue(strategy.maxInterval)) - } - - "should not fail, if there is many attempts" in { - assert(strategy.on(1000) == OnAttempt.Continue(strategy.maxInterval)) - } - } - } - } - - "complete" - { - "onComplete == mark" - { - "should update the item" in { - var done = false - val item = defaultItem - - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - - override def delete(kind: String, tag: String): Unit = throw new IllegalStateException("Impossible call") - - override def update(entity: EntityT): EntityT = { - assert(entity.kind == item.kind, "repository.delete, kind") - assert(entity.tag == item.tag, "repository.delete, tag") - done = true - entity - } - - override def getById(kind: String, tag: String): Option[EntityT] = Some(item) - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = Strategy.Stop(OnComplete.Mark), - repository = repository, - dbIo = FakeDbIo - ) - - assert(adapter.complete(item.kind, item.tag).isReadyWithin(100.millis)) - assert(done) - } - } - - "onComplete == delete" - { - "should delete the item" in { - var done = false - val item = defaultItem - - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - - override def delete(kind: String, tag: String): Unit = { - assert(kind == item.kind, "repository.delete, kind") - assert(tag == item.tag, "repository.delete, tag") - done = true - } - override def update(entity: EntityT): EntityT = throw new IllegalStateException("Impossible call") - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = Strategy.Stop(OnComplete.Delete), - repository = repository, - dbIo = FakeDbIo - ) - - assert(adapter.complete(item.kind, item.tag).isReadyWithin(100.millis)) - assert(done) - } - } - } - - "tryRetry" - { - - "when all attempts are not out" - { - - val defaultStrategy = Strategy.Constant(10.seconds) - - "should return an updated item" in { - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - - override def update(draft: EntityT): EntityT = draft - override def delete(kind: String, tag: String): Unit = throw new IllegalAccessError(s"kind=$kind, tag=$tag") - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = defaultStrategy, - repository = repository, - dbIo = FakeDbIo - ) - - val item = defaultItem - val r = adapter.tryRetry(item).futureValue - assert(r.isDefined) - assert(!r.contains(item)) - } - - "should update an item with increased attempts" in { - val item = defaultItem - - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - - override def update(draft: EntityT): EntityT = { - assert(draft.attempts === (item.attempts + 1), "repository.add") - draft - } - override def delete(kind: String, tag: String): Unit = throw new IllegalAccessError(s"kind=$kind, tag=$tag") - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = defaultStrategy, - repository = repository, - dbIo = FakeDbIo - ) - - assert(adapter.tryRetry(item).isReadyWithin(100.millis)) - } - - "should remove an old item" in { - val item = defaultItem - - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - override def update(draft: EntityT): EntityT = draft - override def delete(kind: String, tag: String): Unit = { - assert(kind == item.kind, "repository.delete, kind") - assert(tag == item.tag, "repository.delete, kind") - } - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = defaultStrategy, - repository = repository, - dbIo = FakeDbIo - ) - - assert(adapter.tryRetry(item).isReadyWithin(100.millis)) - } - - "should update time of the next attempt" in { - val item = defaultItem - - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - - override def update(draft: EntityT): EntityT = { - assert(draft.nextAttempt.isAfter(item.nextAttempt), "repository.add") - draft - } - override def delete(kind: String, tag: String): Unit = throw new IllegalAccessError(s"kind=$kind, tag=$tag") - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = defaultStrategy, - repository = repository, - dbIo = FakeDbIo - ) - - assert(adapter.tryRetry(item).isReadyWithin(100.millis)) - } - - } - - "when all attempts are out" - { - - val defaultStrategy = Strategy.Stop() - - "should not return an item" in { - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - override def update(entity: EntityT): EntityT = fail("update should not be used!") - - override def delete(kind: String, tag: String): Unit = {} - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = defaultStrategy, - repository = repository, - dbIo = FakeDbIo - ) - - val r = adapter.tryRetry(defaultItem).futureValue - assert(r.isEmpty) - } - - "should complete the item" in { - var taskWasCompleted = false - val item = defaultItem - - val repository = new BridgeUploadQueueRepository { - override def add(draft: EntityT): EntityT = draft - override def getOne(kind: String): Option[EntityT] = fail("getOne should not be used!") - override def buildQuery: MysqlQueryBuilder[EntityT] = fail("buildQuery should not be used!") - override def getById(kind: String, tag: String): Option[EntityT] = fail("getById should not be used!") - override def update(entity: EntityT): EntityT = fail("update should not be used!") - - override def delete(kind: String, tag: String): Unit = {} - } - - val adapter = new BridgeUploadQueueRepositoryAdapter( - strategy = defaultStrategy, - repository = repository, - dbIo = FakeDbIo - ) { - override def complete(kind: String, tag: String): Future[Unit] = Future { - assert(kind == item.kind, "adapter.complete, kind") - assert(tag == item.tag, "adapter.complete, tag") - taskWasCompleted = true - } - } - - val r = adapter.tryRetry(item).futureValue - assert(r.isEmpty) - assert(taskWasCompleted) - } - - } - - } - - private def defaultItem = BridgeUploadQueue.Item( - "test", - ThreadLocalRandom.current().nextInt().toString - ) - -} diff --git a/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala deleted file mode 100644 index 2c23b92..0000000 --- a/src/test/scala/xyz/driver/pdsuicommon/db/QueryBuilderParametersSuite.scala +++ /dev/null @@ -1,310 +0,0 @@ -package xyz.driver.pdsuicommon.db - -import java.time.LocalDateTime - -import io.getquill.MysqlEscape -import org.scalatest.FreeSpecLike -import xyz.driver.pdsuicommon.db.QueryBuilder.TableData -import xyz.driver.pdsuicommon.domain._ - -class QueryBuilderParametersSuite extends FreeSpecLike { - - import SearchFilterBinaryOperation._ - import SearchFilterExpr.{Dimension => _, _} - import SearchFilterNAryOperation._ - import Sorting._ - import SortingOrder._ - - val tableName = "Entity" - - case class Entity(id: LongId[Entity], - name: String, - email: Email, - optionUser: Option[StringId[User]], - date: LocalDateTime, - optionDate: Option[LocalDateTime], - kindId: Long) - - def queryBuilderParameters = MysqlQueryBuilderParameters( - tableData = TableData( - tableName = tableName, - nullableFields = Set("optionUser", "optionDate") - ), - links = Map( - "Kind" -> TableLink("kindId", "Kind", "id"), - "User" -> TableLink("optionUser", "User", "id") - ) - ) - - val queryBasis = - s"""select `$tableName`.* - |from `$tableName`""".stripMargin.trim - - "toSql" - { - "should generate correct SQL query" - { - "with default parameters" in { - val (sql, _) = queryBuilderParameters.toSql(namingStrategy = MysqlEscape) - assert(sql == queryBasis) - } - - "with filtering: " - { - "single atom filter" in { - val (sql, _) = - queryBuilderParameters.copy(filter = Atom.Binary("name", Eq, "x")).toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |where `$tableName`.`name` = ?""".stripMargin) - } - - "single atom filter for optional field with NotEq operation" in { - val (sql, _) = queryBuilderParameters - .copy(filter = Atom.Binary("optionUser", NotEq, "x")) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |where (`$tableName`.`optionUser` is null or `$tableName`.`optionUser` != ?)""".stripMargin) - } - - "single atom filter for field with IN operation" in { - val (sql, _) = queryBuilderParameters - .copy(filter = Atom.NAry("date", In, Seq("x", "x", "x"))) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |where `$tableName`.`date` in (?, ?, ?)""".stripMargin) - } - - "multiple intersected filters" in { - val (sql, _) = queryBuilderParameters - .copy( - filter = Intersection( - Seq( - Atom.Binary("name", Gt, "x"), - Atom.Binary("optionDate", GtEq, "x") - ))) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |where (`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?)""".stripMargin) - } - - "multiple intersected nested filters" in { - val (sql, _) = queryBuilderParameters - .copy( - filter = Intersection( - Seq( - Atom.Binary("name", Gt, "x"), - Atom.Binary("optionDate", GtEq, "x"), - Intersection(Seq( - Atom.Binary("optionUser", Eq, "x"), - Atom.Binary("date", LtEq, "x") - )) - ))) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"$queryBasis\nwhere (`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?" + - s" and (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))") - } - - "multiple unionized filters" in { - val (sql, _) = queryBuilderParameters - .copy( - filter = Union( - Seq( - Atom.Binary("name", Gt, "x"), - Atom.Binary("optionDate", GtEq, "x") - ))) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |where (`$tableName`.`name` > ? or `$tableName`.`optionDate` >= ?)""".stripMargin.trim) - } - - "multiple unionized nested filters" in { - val (sql, _) = queryBuilderParameters - .copy( - filter = Union( - Seq( - Atom.Binary("name", Gt, "x"), - Atom.Binary("optionDate", GtEq, "x"), - Union(Seq( - Atom.Binary("optionUser", Eq, "x"), - Atom.Binary("date", LtEq, "x") - )) - ))) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |where (`$tableName`.`name` > ? or `$tableName`.`optionDate` >= ? or (`$tableName`.`optionUser` = ? or `$tableName`.`date` <= ?))""".stripMargin) - } - - "multiple unionized and intersected nested filters" in { - val (sql, _) = queryBuilderParameters - .copy(filter = Union(Seq( - Intersection(Seq( - Atom.Binary("name", Gt, "x"), - Atom.Binary("optionDate", GtEq, "x") - )), - Intersection(Seq( - Atom.Binary("optionUser", Eq, "x"), - Atom.Binary("date", LtEq, "x") - )) - ))) - .toSql(namingStrategy = MysqlEscape) - - assert( - sql == - s"$queryBasis\nwhere ((`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?) " + - s"or (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?))") - } - - "single field from foreign table" in { - val (sql, _) = queryBuilderParameters - .copy(filter = Atom.Binary(SearchFilterExpr.Dimension(Some("Kind"), "name"), Eq, "x")) - .toSql(namingStrategy = MysqlEscape) - val pattern = - s"""select `$tableName`.* - |from `$tableName` - |inner join `Kind` on `Entity`.`kindId` = `Kind`.`id` - |where `Kind`.`name` = ?""".stripMargin - assert(sql == pattern) - } - } - - "with sorting:" - { - "single field sorting" in { - val (sql, _) = queryBuilderParameters - .copy(sorting = Dimension(None, "name", Ascending)) - .toSql(namingStrategy = MysqlEscape) - - assert( - sql == - s"""$queryBasis - |order by `$tableName`.`name` asc""".stripMargin) - } - - "single foreign sorting field" in { - val (sql, _) = queryBuilderParameters - .copy(sorting = Dimension(Some("Kind"), "name", Ascending)) - .toSql(namingStrategy = MysqlEscape) - - assert( - sql == - s"""select `$tableName`.* - |from `$tableName` - |inner join `Kind` on `Entity`.`kindId` = `Kind`.`id` - |order by `Kind`.`name` asc""".stripMargin) - } - - "multiple fields sorting" in { - val (sql, _) = queryBuilderParameters - .copy( - sorting = Sequential( - Seq( - Dimension(None, "name", Ascending), - Dimension(None, "date", Descending) - ))) - .toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |order by `$tableName`.`name` asc, `$tableName`.`date` desc""".stripMargin) - } - - "multiple foreign sorting field" in { - val (sql, _) = queryBuilderParameters - .copy( - sorting = Sequential( - Seq( - Dimension(Some("Kind"), "name", Ascending), - Dimension(Some("User"), "name", Descending) - ))) - .toSql(namingStrategy = MysqlEscape) - - assert( - sql == - s"""select `$tableName`.* - |from `$tableName` - |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id` - |inner join `User` on `$tableName`.`optionUser` = `User`.`id` - |order by `Kind`.`name` asc, `User`.`name` desc""".stripMargin) - } - - "multiple field sorting (including foreign tables)" in { - val (sql, _) = queryBuilderParameters - .copy( - sorting = Sequential( - Seq( - Dimension(Some("Kind"), "name", Ascending), - Dimension(None, "date", Descending) - ))) - .toSql(namingStrategy = MysqlEscape) - - assert( - sql == - s"""select `$tableName`.* - |from `$tableName` - |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id` - |order by `Kind`.`name` asc, `$tableName`.`date` desc""".stripMargin) - } - } - - "with pagination" in { - val (sql, _) = - queryBuilderParameters.copy(pagination = Some(Pagination(5, 3))).toSql(namingStrategy = MysqlEscape) - assert( - sql == - s"""$queryBasis - |limit 10, 5""".stripMargin) - } - - "combined" in { - val filter = Union( - Seq( - Intersection( - Seq( - Atom.Binary("name", Gt, "x"), - Atom.Binary("optionDate", GtEq, "x") - )), - Intersection( - Seq( - Atom.Binary("optionUser", Eq, "x"), - Atom.Binary("date", LtEq, "x") - )) - )) - val sorting = Sequential( - Seq( - Dimension(Some("Kind"), "name", Ascending), - Dimension(None, "name", Ascending), - Dimension(None, "date", Descending) - )) - - val (sql, _) = queryBuilderParameters - .copy( - filter = filter, - sorting = sorting, - pagination = Some(Pagination(5, 3)) - ) - .toSql(namingStrategy = MysqlEscape) - - assert( - sql == - s"""select `$tableName`.* - |from `$tableName` - |inner join `Kind` on `$tableName`.`kindId` = `Kind`.`id` - |where ((`$tableName`.`name` > ? and `$tableName`.`optionDate` >= ?) or (`$tableName`.`optionUser` = ? and `$tableName`.`date` <= ?)) - |order by `Kind`.`name` asc, `$tableName`.`name` asc, `$tableName`.`date` desc - |limit 10, 5""".stripMargin) - } - - } - } - -} -- cgit v1.2.3