Doobie Integration

The module emil-doobie provides Meta instances for Doobie.

Usage

With sbt:

libraryDependencies += "com.github.eikek" %% "emil-doobie" % "0.15.0"

Description

You can use emil data types MailAddress, SSLType and Mail in your record classes.

import emil._

case class Record(from: MailAddress, recipients: List[MailAddress], ssl: SSLType, mime: MimeType)

In order to use these types in SQL, you need to import instances defined in emil.doobie.EmilDoobieMeta.

import emil.doobie.EmilDoobieMeta._
import _root_.doobie.implicits._

val r = Record(
  MailAddress.unsafe(Some("Mr. Me"), "me@example.com"),
  List(
    MailAddress.unsafe(Some("Mr. Mine"), "mine_2@example.com"),
    MailAddress.unsafe(Some("Mr. Me"), "me@example.com"),
    MailAddress.unsafe(Some("Mr. You"), "you@example.com")
  ),
  SSLType.StartTLS,
  MimeType.textHtml
)
// r: Record = Record(
//   from = MailAddress(name = Some(value = "Mr. Me"), address = "me@example.com"),
//   recipients = List(
//     MailAddress(name = Some(value = "Mr. Mine"), address = "mine_2@example.com"),
//     MailAddress(name = Some(value = "Mr. Me"), address = "me@example.com"),
//     MailAddress(name = Some(value = "Mr. You"), address = "you@example.com")
//   ),
//   ssl = StartTLS,
//   mime = MimeType(
//     primary = "text",
//     sub = "html",
//     params = Map("charset" -> "UTF-8")
//   )
// )

val insertRecord = sql"""
  insert into mailaddress(sender, recipients, ssl)
  values(${r.from}, ${r.recipients}, ${r.ssl}, ${r.mime})
""".update.run
// insertRecord: <none>.<root>.doobie.package.ConnectionIO[Int] = Suspend(
//   a = Uncancelable(
//     body = cats.effect.kernel.MonadCancel$$Lambda$2255/0x0000000801886d60@677b5145
//   )
// )