Skunk Support
This module provides refined types Codec/Encoder/Decoder instances for Skunk.
Dependency
SBT:
libraryDependencies += "io.github.iltotore" %% "iron-skunk" % "version"
Mill:
ivy"io.github.iltotore::iron-skunk:version"
Following examples' dependencies
SBT:
libraryDependencies += "org.tpolecat" %% "skunk-core" % "0.6.1"
Mill:
ivy"org.tpolecat::skunk-core::0.6.1"
Codec instances
Iron provides Codec
instances for refined types:
import skunk.*
import skunk.implicits.*
import skunk.codec.all.*
import io.github.iltotore.iron.*
import io.github.iltotore.iron.constraint.all.*
import io.github.iltotore.iron.skunk.*
import io.github.iltotore.iron.skunk.given
type Username = String :| Not[Blank]
// refining a codec at usage site
val a: Query[Void, Username] = sql"SELECT name FROM users".query(varchar.refined)
// defining a codec for a refined opaque type
opaque type PositiveInt = Int :| Positive
object PositiveInt extends RefinedTypeOps[Int, Positive, PositiveInt]:
given codec: Codec[PositiveInt] = int4.refined[Positive]
// defining a codec for a refined case class
final case class User(name: Username, age: Int :| Positive)
given Codec[User] = (varchar.refined[Not[Blank]] *: PositiveInt.codec).to[User]
In this article