slick/slick-cats

Name: slick-cats

Owner: Scala Language-Integrated Connection Kit

Description: Cats instances for Slick DBIO

Forked from: RMSone/slick-cats

Created: 2016-12-03 22:21:57.0

Updated: 2016-12-03 22:34:09.0

Pushed: 2016-12-03 17:26:47.0

Homepage: null

Size: 27

Language: Scala

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

SlickCats

Cats instances for Slick's DBIO including:

Using

SlickCats is not yet published but can be used by publishing locally via sbt publishLocal and then adding the following to your build definition:

aryDependencies += "com.rms.miu" %% "slick-cats" % version

Because of possible binary incompatibilities here are the dependency versions used in each release

| slick-cats version | slick version | cats version | |:——————:|:————-:|:————:| | 0.1 | 3.1.1 | 0.5.0 | | 0.2 | 3.1.1 | 0.6.0 | | 0.3 | 3.1.1 | 0.7.0 |

Accessing the Instances

Some or all of the following imports may be needed:

rt cats._
rt cats.implicits._
rt slick.dbio._
rt com.rms.miu.slickcats.DBIOInstances._

Additionally, be sure to have an implicit ExecutionContext in scope. The implicit conversions require it and will fail with non obvious errors if it's missing.

a> implicitly[Monad[DBIO]]
sole>:25: error: could not find implicit value for parameter e: cats.Monad[slick.dbio.DBIO]
   implicitly[Monad[DBIO]]
             ^
cala
rt scala.concurrent.ExecutionContext.Implicits.global

instances will be available for:

icitly[Monad[DBIO]]
icitly[MonadError[DBIO, Throwable]]
icitly[CoflatMap[DBIO]]
icitly[Functor[DBIO]]
icitly[Applicative[DBIO]]

If a Monoid exists for A, here taken as Int, then the following is also available

icitly[Group[DBIO[Int]]]
icitly[Semigroup[DBIO[Int]]]
icitly[Monoid[DBIO[Int]]]
Known Issues

Instances are supplied for DBIO[A] only. Despite being the same thing, type aliases will not match for implicit conversion. This means that the following

a> def monad[F[_] : Monad, A](fa: F[A]): F[A] = fa
d: [F[_], A](fa: F[A])(implicit evidence$1: cats.Monad[F])F[A]

a> val fail1: DBIOAction[String, NoStream, Effect.All] = DBIO.successful("hello")
1: slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect.All] = SuccessAction(hello)

a> val fail2 = DBIO.successful("hello")
2: slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect] = SuccessAction(hello)

a> val success: DBIO[String] = DBIO.successful("hello")
ess: slick.dbio.DBIO[String] = SuccessAction(hello)

will not compile

a> monad(fail1)
sole>:28: error: no type parameters for method monad: (fa: F[A])(implicit evidence$1: cats.Monad[F])F[A] exist so that it can be applied to arguments (slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect.All])
 because ---
ment expression's type is not compatible with formal parameter type;
nd   : slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect.All]
uired: ?F[?A]
   monad(fail1)
   ^
sole>:28: error: type mismatch;
nd   : slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect.All]
uired: F[A]
   monad(fail1)
         ^

a> monad(fail2)
sole>:28: error: no type parameters for method monad: (fa: F[A])(implicit evidence$1: cats.Monad[F])F[A] exist so that it can be applied to arguments (slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect])
 because ---
ment expression's type is not compatible with formal parameter type;
nd   : slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect]
uired: ?F[?A]
   monad(fail2)
   ^
sole>:28: error: type mismatch;
nd   : slick.dbio.DBIOAction[String,slick.dbio.NoStream,slick.dbio.Effect]
uired: F[A]
   monad(fail2)
         ^

but

a> monad(success)
1: slick.dbio.DBIO[String] = SuccessAction(hello)

will compile fine.

Extras

This README is compiled using tut to ensure that only working examples are given. Feedback of any kind is appreciated. Especially if you have any ideas on getting around the DBIOAction issue above.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.