Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created March 26, 2019 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasuabe/b9382687a9ea70b407431833e95d0de8 to your computer and use it in GitHub Desktop.
Save yasuabe/b9382687a9ea70b407431833e95d0de8 to your computer and use it in GitHub Desktop.
simple program for examining Doobie with Monix Task
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