Skip to content

Commit

Permalink
feature: Add doobie support (#184)
Browse files Browse the repository at this point in the history
Co-authored-by: vbergeron <[email protected]>
  • Loading branch information
vbergeron and vbergeron-ledger authored Nov 6, 2023
1 parent c8cdbce commit 6b969dc
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,14 @@ object scalacheck extends SubModule {

object test extends Tests
}

object doobie extends SubModule {

def artifactName = "iron-doobie"

def ivyDeps = Agg(
ivy"org.tpolecat::doobie-core::1.0.0-RC4"
)

object test extends Tests
}
27 changes: 27 additions & 0 deletions doobie/src/io/github/iltotore/iron/doobie.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.github.iltotore.iron

import cats.Show
import _root_.doobie.{Put, Get, Meta}

/**
* Implicit [[Meta]]s, [[Put]]s and [[Get]]s for refined types.
*/
object doobie:

inline given[A, C] (using inline get: Get[A])(using Constraint[A, C], Show[A]): Get[A :| C] =
get.temap[A :| C](_.refineEither)

inline given[T](using m: RefinedTypeOps.Mirror[T], ev: Get[m.IronType]): Get[T] =
ev.asInstanceOf[Get[T]]

inline given[A, C] (using inline put: Put[A])(using Constraint[A, C], Show[A]): Put[A :| C] =
put.tcontramap(identity)

inline given[T](using m: RefinedTypeOps.Mirror[T], ev: Put[m.IronType]): Put[T] =
ev.asInstanceOf[Put[T]]

inline given[A, C] (using inline meta: Meta[A])(using Constraint[A, C], Show[A]): Meta[A :| C] =
meta.tiemap[A :| C](_.refineEither)(identity)

inline given[T](using m: RefinedTypeOps.Mirror[T], ev: Meta[m.IronType]): Meta[T] =
ev.asInstanceOf[Meta[T]]

0 comments on commit 6b969dc

Please sign in to comment.