Skip to content

Instantly share code, notes, and snippets.

@dsebban
Last active November 29, 2022 09:37
Show Gist options
  • Save dsebban/7a2b4245e0545230cd65450ca47d1b15 to your computer and use it in GitHub Desktop.
Save dsebban/7a2b4245e0545230cd65450ca47d1b15 to your computer and use it in GitHub Desktop.
// val skunkCore = "0.3.2"
// val zioCats = "3.3.0"
// val zioStreams = "2.0.0"
// val skunkCore = "org.tpolecat" %% "skunk-core" % V.skunkCore
// val zioCats = "dev.zio" %% "zio-interop-cats" % V.zioCats
// val zioStreams = "dev.zio" %% "zio-streams" % V.zioStreams
object Cats {
import skunk._
import skunk.implicits._
import skunk.codec.all._
import natchez.Trace.Implicits.noop
import cats.effect._
import natchez.Trace
import fs2.io.net.Network
import cats.effect.std.Console
def catsProgram[F[_]: cats.effect.Async: Network: Console] = {
val session =
Session.single( // (2)
host = "localhost",
port = 5432,
user = "jimmy",
database = "world",
password = Some("banana")
)
session.use { s => // (3)
s.unique(sql"select current_date".query(date)) // (4)
}
}
}
object ZioCatsEffectInteropWithCatsApp extends zio.interop.catz.CatsApp {
import fs2.io.net.Network
import cats.effect._
def catsEffectApp[F[_]: cats.effect.Async: Network: std.Console] =
Cats.catsProgram
import zio.interop.catz._
import zio.interop.console._
import zio.interop.catz.implicits._
import zio.Console._
override def run = {
implicit val consoleInst: std.Console[zio.Task] = std.Console.make
val zioApp = catsEffectApp[zio.Task]
(for {
d <- zioApp
_ <- printLine(s"The current date is $d.")
} yield d).exitCode
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment