Skip to content

Conversation

@stankoua
Copy link
Collaborator

No description provided.


def fetchMaterial(id: Int): SqlQuery[Option[Material]] = {
SqlQuery { implicit connection =>
SQL"SELECT * FROM materials where id = {id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$id

} yield (professor, material)
val resF = runner(query)
val result = Await.result(resF, 1.minute)
result aka "professor and material" mustEqual None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beNone

val result = Await.result(resF, 1.minute)
result aka "professor and material" mustEqual Tuple2(
Professor(1, "John Doe", 35, 1),
Material(1, "Computer Science", 20, "Beginner"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.await

build.sbt Outdated
name := "query-core",
libraryDependencies ++= Seq(
Dependencies.cats
Dependencies.acolyte,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% Test

type QueryO[Resource, A] = QueryT[Option, Resource, A]

type QueryE[Resource, A, Err] =
object QueryO {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplication par rapport à généricité sur QueryT

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je trouve un peu frustrant d'avoir un type dans l'api (pour améliorer la lisibilité) et de devoir faire appel au companion du type générique pour construire son instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Une proposition alternative que je pourrai faire c'est d'extraire les fonctions de QueryT et de les mettre dans un trait partagé par les companions objects QueryT, QueryO et QueryE. @cchantep qu'en penses-tu ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pour moi ces objects ne sont que des convenient instances de QueryT, dupliquer toute la logique apply, pure, ask, liftF, fromQuery ne me semble pas approprié.


type SqlQueryO[A] = QueryO[Connection, A]

object SqlQueryO {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplication

SqlConnectionFactory.withSqlConnection(AcolyteQueryResult.Nil)
val runner = SqlQueryRunner(withSqlConnection)
val query = SqlQuery.pure(1)
val resF = runner(query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runner(query) must beTypedEqualTo(1).await

_ <- SqlQuery.ask
professor <- Professor.fetchProfessor(2)
} yield professor
val resF = runner(query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runner(query) must beNone.await


// execute composed queries into a single transaction
"retrieve professor with id 1 and his material" in {
val handler = AcolyteDSL.handleStatement
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a query only handler, AcolyteDSL.handleQuery { .. }


def fetchProfessor(id: Int): SqlQuery[Option[Professor]] = {
SqlQuery { implicit connection =>
SQL"SELECT * FROM professors where id = {id}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$id

implicit ec: ExecutionContext
) extends QueryRunner[Resource] {

def apply[M[_], T](query: QueryT[M, Resource, T]): Future[M[T]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!! Si M = Future

Copy link
Collaborator Author

@stankoua stankoua Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effectivement. Mais je trouve ça commode de pouvoir run directement un QueryT sans avoir à repasser à une Query. Je pourrai essayer de restreindre en demandant une evidence en implicit mais j'ai plutôt envie de dire que c'est à l'utilisateur de gérer ça.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sauf que le loan pattern ne gèrera pas correctement (ça échouera) la ressource si le traitement Query se base sur M=Future

@stankoua stankoua force-pushed the task/setup-testing branch 3 times, most recently from 84912d9 to fee481c Compare February 20, 2018 00:34
type Outer = Future[F[A]]

def apply[In](resource: In, f: In => F[A])(onComplete: In => Unit)(implicit ec: ExecutionContext): Outer = {
Try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/* ? */ Future(f(resource)).andThen { case _ => onComplete(resource) }

SqlConnectionFactory.withSqlConnection(AcolyteQueryResult.Nil)
val runner = SqlQueryRunner(withSqlConnection)
val query = SqlQuery.pure(1)
runner(query) aka "material" must beTypedEqualTo(1).await
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J'aèrerais avec une ligne d'espace entre le bloc de déclaration/val et l'expectation

SqlQueryT{implicit c =>
Future {
Thread.sleep(2000) // Simumlates a a very slow query
val r = SQL"select sqrt($num) as result".as(SqlParser.double("result").single)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val r = ...; r => ... ?

@cchantep
Copy link
Contributor

@stankoua Sur les tests, tu as un soucis de cohérence du formattage : https://travis-ci.org/zengularity/query-monad/builds/354037179#L504

/**
* Heavily inspired from work done by @cchantep in Acolyte (see acolyte.reactivemongo.ComposeWithCompletion)
*/
* Heavily inspired from work done by @cchantep in Acolyte (see acolyte.reactivemongo.ComposeWithCompletion)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent issue

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I have an issue with scalafmt which doesn't format properly scaladoc. I'm working on an PR to update scalafmt settings.

@stankoua stankoua merged commit 2e20857 into master Apr 13, 2018
@stankoua stankoua deleted the task/setup-testing branch April 13, 2018 15:19
@stankoua stankoua mentioned this pull request Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants