Created
March 26, 2019 22:16
-
-
Save yasuabe/b9382687a9ea70b407431833e95d0de8 to your computer and use it in GitHub Desktop.
simple program for examining Doobie with Monix Task
This file contains hidden or 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
package doobie_top | |
import doobie._ | |
import doobie.implicits._ | |
import cats.effect._ | |
import monix.eval.{Task, TaskApp} | |
case class Country(code: String, name: String, population: Long) | |
object SimpleSampleMain extends TaskApp { | |
def xa[F[_]: Async: ContextShift]: Transactor[F] = Transactor.fromDriverManager[F]( | |
"org.postgresql.Driver", "jdbc:postgresql:world", "postgres", "pass" | |
) | |
def find(n: String): ConnectionIO[Option[Country]] = | |
sql"select code, name, population from country where name = $n".query[Country].option | |
def run(args: List[String]): Task[ExitCode] = for { | |
line <- find("France").transact(xa[Task]) // ConnectionIO[_] ~> Task[_] | |
_ <- Task { println(line) } | |
} yield ExitCode.Success | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment