Skip to content

Commit

Permalink
Remove typeclass annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kubukoz committed Oct 1, 2018
1 parent 5adb544 commit a1f6c70
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
@@ -1,14 +1,14 @@
package com.kubukoz.slick.algebra
import com.kubukoz.slick.interpreter.DBIOInterpreter
import simulacrum.typeclass
import slick.lifted.{Query => LiftedQuery}

@typeclass
trait SelectAlgebra[F[_]] {
def result[T, E, S[_]](query: LiftedQuery[T, E, S]): F[S[E]]
}

object SelectAlgebra {
def apply[F[_]: SelectAlgebra]: SelectAlgebra[F] = implicitly

implicit def derive[F[_]: DBIOInterpreter]: SelectAlgebra[F] = new InterpSelectAlgebra[F] {
override protected def interpreter: DBIOInterpreter[F] = DBIOInterpreter[F]
}
Expand Down
@@ -1,15 +1,16 @@
package com.kubukoz.slick.algebra

import com.kubukoz.slick.interpreter.StreamingDBIOInterpreter
import fs2.Stream
import simulacrum.typeclass
import slick.lifted.{Query => LiftedQuery}

@typeclass
trait StreamingSelectAlgebra[F[_]] extends SelectAlgebra[F] {
def stream[T, E, S[_]](query: LiftedQuery[T, E, S]): Stream[F, E]
}

object StreamingSelectAlgebra {
def apply[F[_]: StreamingSelectAlgebra]: StreamingSelectAlgebra[F] = implicitly

implicit def derive[F[_]: StreamingDBIOInterpreter]: StreamingSelectAlgebra[F] = new InterpStreamingAlgebra[F] {
override protected def interpreter: StreamingDBIOInterpreter[F] = StreamingDBIOInterpreter[F]
}
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/scala/com/kubukoz/slick/examples/profiles.scala
@@ -1,11 +1,10 @@
package com.kubukoz.slick.examples

import cats.implicits._
import cats.effect._
import cats.implicits._
import com.kubukoz.slick.algebra.StreamingSelectAlgebra
import com.kubukoz.slick.interpreter.StreamingDBIOInterpreter
import fs2.Stream
import slick.basic.DatabasePublisher
import slick.jdbc.{JdbcProfile, PostgresProfile}
import slick.lifted.{ProvenShape, TableQuery}

Expand All @@ -31,9 +30,9 @@ object Tests extends IOApp {
Database.forURL("jdbc:postgresql://localhost/postgres", "postgres", "example", driver = "org.postgresql.Driver")

def program[F[_]: StreamingSelectAlgebra]: Stream[F, Int] = {
StreamingSelectAlgebra[F].stream(
StreamingSelectAlgebra[F].stream {
TableQuery[Users].map(_.age)
)
}
}

override def run(args: List[String]): IO[ExitCode] = {
Expand Down
Expand Up @@ -4,11 +4,9 @@ import cats.effect.Async
import cats.~>
import com.kubukoz.slick.interpreter.DBIOInterpreter.WithApi
import com.kubukoz.slick.interpreter.internal.AsyncUtils
import simulacrum.typeclass
import slick.dbio._
import slick.jdbc.JdbcProfile

@typeclass
trait DBIOInterpreter[F[_]] {
def profile: JdbcProfile

Expand All @@ -18,6 +16,7 @@ trait DBIOInterpreter[F[_]] {
}

object DBIOInterpreter {
def apply[F[_]: DBIOInterpreter]: DBIOInterpreter[F] = implicitly

def interpreter[F[_]: Async](profile: JdbcProfile, db: JdbcProfile#API#Database): DBIOInterpreter[F] = {
new AsyncInterpreter[F](profile, db) {
Expand Down
Expand Up @@ -3,16 +3,15 @@ package com.kubukoz.slick.interpreter
import cats.effect.{Async, ConcurrentEffect}
import cats.~>
import fs2.Stream
import simulacrum.typeclass
import slick.dbio.StreamingDBIO
import slick.jdbc.JdbcProfile

@typeclass
trait StreamingDBIOInterpreter[F[_]] extends DBIOInterpreter[F] {
def stream[R]: StreamingDBIO[R, ?] ~> Stream[F, ?]
}

object StreamingDBIOInterpreter {
def apply[F[_]: StreamingDBIOInterpreter]: StreamingDBIOInterpreter[F] = implicitly

def streamingInterpreter[F[_]: ConcurrentEffect](profile: JdbcProfile,
db: JdbcProfile#API#Database): StreamingDBIOInterpreter[F] =
Expand Down

0 comments on commit a1f6c70

Please sign in to comment.