Skip to content

Instantly share code, notes, and snippets.

@adamw
Last active September 20, 2019 06:19
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 adamw/008d4bc70326375c55ded513fa55d075 to your computer and use it in GitHub Desktop.
Save adamw/008d4bc70326375c55ded513fa55d075 to your computer and use it in GitHub Desktop.
val countPersons: ConnectionIO[Int] =
sql"SELECT COUNT(*) FROM persons".query[Int].unique
val callFromCount: ConnectionIO[IO[Unit]] = countPersons.map { count =>
if (count == 0) IO(println("No users!")) else IO(println(s"Found $count users"))
}
val showResults: IO[Unit] = callFromCount.transact(transactor).flatten
showResults.unsafeRunSync()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment