Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add doobie support #184

Merged
merged 5 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,16 @@ 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 js extends JSCrossModule

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 doobie.util.{Put, Get, Meta}
vbergeron marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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]]
Loading