forked from zio/zio-quill
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zio#957 from deusaquilus/master
Ad-Hoc Tuple Support in Quotations
- Loading branch information
Showing
36 changed files
with
983 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...-async-mysql/src/test/scala/io/getquill/context/async/mysql/CaseClassQueryAsyncSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.getquill.context.async.mysql | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.{ global => ec } | ||
import io.getquill.context.sql.CaseClassQuerySpec | ||
import org.scalatest.Matchers._ | ||
|
||
class CaseClassQueryAsyncSpec extends CaseClassQuerySpec { | ||
|
||
val context = testContext | ||
import testContext._ | ||
|
||
override def beforeAll = | ||
await { | ||
testContext.transaction { implicit ec => | ||
for { | ||
_ <- testContext.run(query[Contact].delete) | ||
_ <- testContext.run(query[Address].delete) | ||
_ <- testContext.run(liftQuery(peopleEntries).foreach(e => peopleInsert(e))) | ||
_ <- testContext.run(liftQuery(addressEntries).foreach(e => addressInsert(e))) | ||
} yield {} | ||
} | ||
} | ||
|
||
"Example 1 - Single Case Class Mapping" in { | ||
await(testContext.run(`Ex 1 CaseClass Record Output`)) should contain theSameElementsAs `Ex 1 CaseClass Record Output expected result` | ||
} | ||
"Example 1A - Single Case Class Mapping" in { | ||
await(testContext.run(`Ex 1A CaseClass Record Output`)) should contain theSameElementsAs `Ex 1 CaseClass Record Output expected result` | ||
} | ||
"Example 1B - Single Case Class Mapping" in { | ||
await(testContext.run(`Ex 1B CaseClass Record Output`)) should contain theSameElementsAs `Ex 1 CaseClass Record Output expected result` | ||
} | ||
|
||
"Example 2 - Single Record Mapped Join" in { | ||
await(testContext.run(`Ex 2 Single-Record Join`)) should contain theSameElementsAs `Ex 2 Single-Record Join expected result` | ||
} | ||
|
||
"Example 3 - Inline Record as Filter" in { | ||
await(testContext.run(`Ex 3 Inline Record Usage`)) should contain theSameElementsAs `Ex 3 Inline Record Usage exepected result` | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...-postgres/src/test/scala/io/getquill/context/async/postgres/CaseClassQueryAsyncSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.getquill.context.async.postgres | ||
|
||
import scala.concurrent.ExecutionContext.Implicits.{ global => ec } | ||
import io.getquill.context.sql.CaseClassQuerySpec | ||
import org.scalatest.Matchers._ | ||
|
||
class CaseClassQueryAsyncSpec extends CaseClassQuerySpec { | ||
|
||
val context = testContext | ||
import testContext._ | ||
|
||
override def beforeAll = | ||
await { | ||
testContext.transaction { implicit ec => | ||
for { | ||
_ <- testContext.run(query[Contact].delete) | ||
_ <- testContext.run(query[Address].delete) | ||
_ <- testContext.run(liftQuery(peopleEntries).foreach(e => peopleInsert(e))) | ||
_ <- testContext.run(liftQuery(addressEntries).foreach(e => addressInsert(e))) | ||
} yield {} | ||
} | ||
} | ||
|
||
"Example 1 - Single Case Class Mapping" in { | ||
await(testContext.run(`Ex 1 CaseClass Record Output`)) should contain theSameElementsAs `Ex 1 CaseClass Record Output expected result` | ||
} | ||
"Example 1A - Single Case Class Mapping" in { | ||
await(testContext.run(`Ex 1A CaseClass Record Output`)) should contain theSameElementsAs `Ex 1 CaseClass Record Output expected result` | ||
} | ||
"Example 1B - Single Case Class Mapping" in { | ||
await(testContext.run(`Ex 1B CaseClass Record Output`)) should contain theSameElementsAs `Ex 1 CaseClass Record Output expected result` | ||
} | ||
|
||
"Example 2 - Single Record Mapped Join" in { | ||
await(testContext.run(`Ex 2 Single-Record Join`)) should contain theSameElementsAs `Ex 2 Single-Record Join expected result` | ||
} | ||
|
||
"Example 3 - Inline Record as Filter" in { | ||
await(testContext.run(`Ex 3 Inline Record Usage`)) should contain theSameElementsAs `Ex 3 Inline Record Usage exepected result` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...-cassandra/src/test/scala/io/getquill/context/cassandra/CaseClassQueryCassandraSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.getquill.context.cassandra | ||
|
||
import io.getquill.Spec | ||
|
||
class CaseClassQueryCassandraSpec extends Spec { | ||
|
||
import testSyncDB._ | ||
|
||
case class Contact(id: Int, firstName: String, lastName: String, age: Int, addressFk: Int, extraInfo: String) | ||
case class Address(id: Int, street: String, zip: Int, otherExtraInfo: String) | ||
|
||
val peopleInsert = | ||
quote((p: Contact) => query[Contact].insert(p)) | ||
|
||
val peopleEntries = List( | ||
Contact(1, "Alex", "Jones", 60, 2, "foo"), | ||
Contact(2, "Bert", "James", 55, 3, "bar"), | ||
Contact(3, "Cora", "Jasper", 33, 3, "baz") | ||
) | ||
|
||
val addressInsert = | ||
quote((c: Address) => query[Address].insert(c)) | ||
|
||
val addressEntries = List( | ||
Address(1, "123 Fake Street", 11234, "something"), | ||
Address(2, "456 Old Street", 45678, "something else"), | ||
Address(3, "789 New Street", 89010, "another thing") | ||
) | ||
|
||
case class ContactSimplified(firstName: String, lastName: String, age: Int) | ||
case class AddressableContact(firstName: String, lastName: String, age: Int, street: String, zip: Int) | ||
|
||
val `Ex 1 CaseClass Record Output` = quote { | ||
query[Contact].map(p => new ContactSimplified(p.firstName, p.lastName, p.age)) | ||
} | ||
|
||
val `Ex 1 CaseClass Record Output expected result` = List( | ||
ContactSimplified("Alex", "Jones", 60), | ||
ContactSimplified("Bert", "James", 55), | ||
ContactSimplified("Cora", "Jasper", 33) | ||
) | ||
|
||
case class FiltrationObject(idFilter: Int) | ||
|
||
val `Ex 3 Inline Record Usage` = quote { | ||
val filtrationObject = new FiltrationObject(1) | ||
query[Contact].filter(p => p.id == filtrationObject.idFilter) | ||
} | ||
|
||
val `Ex 3 Inline Record Usage exepected result` = List( | ||
new Contact(1, "Alex", "Jones", 60, 2, "foo") | ||
) | ||
|
||
override def beforeAll = { | ||
testSyncDB.run(query[Contact].delete) | ||
testSyncDB.run(query[Address].delete) | ||
testSyncDB.run(liftQuery(peopleEntries).foreach(p => peopleInsert(p))) | ||
testSyncDB.run(liftQuery(addressEntries).foreach(p => addressInsert(p))) | ||
} | ||
|
||
"Example 1 - Single Case Class Mapping" in { | ||
testSyncDB.run(`Ex 1 CaseClass Record Output`) mustEqual `Ex 1 CaseClass Record Output expected result` | ||
} | ||
|
||
"Example 2 - Inline Record as Filter" in { | ||
testSyncDB.run(`Ex 3 Inline Record Usage`) mustEqual `Ex 3 Inline Record Usage exepected result` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.