This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit class OptionFilter[ X, Y ]( query: Query[ X, Y, Seq ] ) { | |
def filteredBy[ T ]( op: Option[ T ] )( f: ( X, T ) => Column[ Option[ Boolean ] ] ): Query[ X, Y, Seq ] = { | |
op map { o => query.filter( f( _, o ) ) } getOrElse { query } | |
} | |
def foundBy[ T ]( op: Option[ T ] )( f: ( X, T ) => Column[ Option[ Boolean ] ] ): Query[ X, Y, Seq ] = { | |
op map { o => query.filter( f( _, o ) ) } getOrElse { query.take( 0 ) } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait SlickQueryOps { | |
databaseConfig: HasDatabaseConfig[ JdbcProfile ] => | |
import cats.Apply | |
import cats.std.list._ | |
import driver.api._ | |
type BooleanOp = ( Rep[ Boolean ], Rep[ Boolean ] ) => Rep[ Boolean ] | |
implicit class OptionFilter[ X, Y ]( query: Query[ X, Y, Seq ] ) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package user.persistence.tables | |
object UserTables { | |
val driver = slick.driver.MySQLDriver | |
import driver.api._ | |
class Users(tag: Tag) extends Table[UserRegister](tag, "USERS") { | |
val username: Rep[ String ] = column[ String ]( "USERNAME", O.PrimaryKey ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package user.persistence.repository | |
import user.persistence.tables.UserRegister | |
import user.persistence.tables.UserTables.Users | |
import play.api.Play | |
import play.api.db.slick.DatabaseConfigProvider | |
import scala.concurrent.Future | |
case class UserFilter(name: Option[ String ] = None, lastname: Option[ String ] = None, | |
email: Option[ String ] = None, username: Option[ String ] = None, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package user.controllers | |
import genesis.user.persistence.repository.{UserFilter, UserRepository} | |
import play.api.libs.json._ | |
import play.api.mvc.{Action, Controller} | |
import scala.concurrent.Future | |
/** | |
* Created by leandrob13 on 10/9/15. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cats.data | |
import cats._ | |
import cats.functor.Contravariant | |
import ListT._ | |
/** | |
* ListT monad transformer. | |
*/ | |
sealed class ListT[M[_], A](val value: M[Step[A, ListT[M, A]]]) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.data.{Kleisli, ListT} | |
import cats.std.list._ | |
type ListTA[A] = ListT[List, A] | |
val (f, g, h, x) = ( | |
(a: Int) => a match { | |
case 0 => ListT.fromList(List(List(0, 1))) | |
case 1 => ListT.fromList(List(List(0), List(1))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cats.data._ | |
import cats.syntax.traverse._ | |
import cats.std.list._ | |
import scala.util.Try | |
def tryInt(s: String): Try[Int] = Try(s.toInt) | |
def reader: Reader[Try[Int], String] = Reader[Try[Int], String] { t => | |
t.map(s => s"$s is a number").getOrElse("not") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected val driver = com.typesafe.slick.driver.oracle.OracleDriver | |
import TperTiposPersonasRegistro._ | |
import driver.api._ | |
class TperTiposPersonas( _tableTag: Tag ) extends Table[TperTiposPersonasRegistro]( _tableTag, None, "TPER_TIPOS_PERSONAS" ) { | |
val cdtipoPersona: Rep[String] = column[String]( "CDTIPO_PERSONA", O.PrimaryKey, O.Length( 2, varying = true ) ) | |
val dstipoPersona: Rep[Option[String]] = column[Option[String]]( "DSTIPO_PERSONA", O.Length( 30, varying = true ) ) | |
val febaja: Rep[Option[Timestamp]] = column[Option[Timestamp]]( "FEBAJA" ) | |
val snnumerico: Rep[Option[Char]] = column[Option[Char]]( "SNNUMERICO" ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lazy val root = (project in file(".")).enablePlugins(PlayScala). | |
settings( | |
slick <<= slickCodeGenTask // register manual sbt command | |
) | |
// code generation task | |
lazy val slick = TaskKey[Seq[File]]("gen-tables") | |
lazy val slickCodeGenTask = (sourceManaged, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) => | |
val outputDir = (dir / "slick").getPath // place generated files in sbt's managed sources folder | |
val url = "jdbc:oracle:thin:@mdebddd06.suranet.com:1537/DLLOLFHA" // connection info for a pre-populated throw-away, in-memory db for this demo, which is freshly initialized on every run |
OlderNewer