Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

EntityActions.idLens requires Option[Id] #74

Open
taitruong opened this issue Dec 4, 2015 · 3 comments
Open

EntityActions.idLens requires Option[Id] #74

taitruong opened this issue Dec 4, 2015 · 3 comments

Comments

@taitruong
Copy link

First of all: great api! I've spent half day implementing my own generic DAO but then I found yours :).

I have a question on your definition of EntityActions.idLens as defined like this in EntityActions:
def idLens: Lens[Entity, Option[Id]]

Wouldn't it be better to have it rather than this below (without Option)?
def idLens: Lens[Entity, Id]

Looking at your documentation on http://www.strongtyped.io/active-slick/ you use the Coffee example where id is optional. But I think this depends and should not be limited by your API. In your example you have this:

object CoffeeRepo extends EntityActions with H2ProfileProvider {
...
type Id = Int //
...
val idLens = lens { coffee: Coffee => coffee.id } //
{ (coffee, id) => coffee.copy(id = id) }
...

In my case all my IDs are mandatory and not optional. Now I have to override idLens by this:
val idLens = lens { entity: Entity => Option(entity.id )} //getter function
{ (entity, id) => entity.copy(id = id.get)} //setter function

Thanks, Tai

@octonato
Copy link
Contributor

octonato commented Dec 4, 2015

Hi @taitruong

Indeed, this could be a nice improvement. Actually, we I think we can even make the Lens typed as:
Lens[Entity, Id] where Id is Option[T] or T or whatever we want.

By the way, since Id is a type member of Entity, it should also be possible to type it as Lens[Entity]

Would you mind to experiment with that and send a pull request? I won't have time to try it myself in the coming days

@taitruong
Copy link
Author

Hi Renato,

I can do this. Unfortunately I am having problems integrating your project into mine as a sub project. I have already spent some hours and have error with multi projects using build.sbt. The error I get is this:

Waiting for lock on /home/ttruong/.sbt/boot/sbt.boot.lock to be available...
[info] Loading project definition from /home/ttruong/IdeaProjects/bi-data-generator/project
/home/ttruong/IdeaProjects/bi-data-generator/active-slick/build.sbt:1: error: not found: object Dependencies
import Dependencies._
^
/home/ttruong/IdeaProjects/bi-data-generator/active-slick/build.sbt:20: error: not found: value projSettings
settings = projSettings ++ Seq(
^
/home/ttruong/IdeaProjects/bi-data-generator/active-slick/build.sbt:30: error: not found: value projSettings
settings = projSettings ++ mainDeps ++ testDeps
^
/home/ttruong/IdeaProjects/bi-data-generator/active-slick/build.sbt:40: error: not found: value shapelessDeps
libraryDependencies ++= shapelessDeps.value
^
/home/ttruong/IdeaProjects/bi-data-generator/active-slick/build.sbt:46: error: not found: value projSettings
settings = projSettings ++ mainDeps ++ shapeless ++ testDeps
^
/home/ttruong/IdeaProjects/bi-data-generator/active-slick/build.sbt:57: error: not found: value projSettings
settings = projSettings ++ Seq(
^
sbt.compiler.EvalException: Type error in expression
at sbt.compiler.Eval.checkError(Eval.scala:384)
at sbt.compiler.Eval.compileAndLoad(Eval.scala:183)
at sbt.compiler.Eval.evalCommon(Eval.scala:152)
at sbt.compiler.Eval.evalDefinitions(Eval.scala:122)
at sbt.EvaluateConfigurations$.evaluateDefinitions(EvaluateConfigurations.scala:271)
at sbt.EvaluateConfigurations$.evaluateSbtFile(EvaluateConfigurations.scala:109)
at sbt.Load$.sbt$Load$$loadSettingsFile$1(Load.scala:712)
at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:717)
at sbt.Load$$anonfun$sbt$Load$$memoLoadSettingsFile$1$1.apply(Load.scala:716)
at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
at scala.collection.AbstractMap.getOrElse(Map.scala:58)
at sbt.Load$.sbt$Load$$memoLoadSettingsFile$1(Load.scala:716)
at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:723)
at sbt.Load$$anonfun$loadFiles$1$2.apply(Load.scala:723)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
at scala.collection.AbstractTraversable.map(Traversable.scala:105)
at sbt.Load$.loadFiles$1(Load.scala:723)
at sbt.Load$.discoverProjects(Load.scala:734)
at sbt.Load$.discover$1(Load.scala:545)
at sbt.Load$.discoverAndLoad$1(Load.scala:554)
at sbt.Load$.loadTransitive(Load.scala:570)
at sbt.Load$.loadProjects$1(Load.scala:442)
at sbt.Load$.loadUnit(Load.scala:446)
at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:281)
at sbt.Load$$anonfun$18$$anonfun$apply$11.apply(Load.scala:281)
at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:91)
at sbt.BuildLoader$$anonfun$componentLoader$1$$anonfun$apply$4$$anonfun$apply$5$$anonfun$apply$6.apply(BuildLoader.scala:90)
at sbt.BuildLoader.apply(BuildLoader.scala:140)
at sbt.Load$.loadAll(Load.scala:334)
at sbt.Load$.loadURI(Load.scala:289)
at sbt.Load$.load(Load.scala:285)
at sbt.Load$.load(Load.scala:276)
at sbt.Load$.apply(Load.scala:130)
at sbt.Load$.defaultLoad(Load.scala:36)
at sbt.BuiltinCommands$.doLoadProject(Main.scala:481)
at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
at sbt.BuiltinCommands$$anonfun$loadProjectImpl$2.apply(Main.scala:475)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
at sbt.Command$$anonfun$applyEffect$1$$anonfun$apply$2.apply(Command.scala:58)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:60)
at sbt.Command$.process(Command.scala:92)
at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:98)
at sbt.State$$anon$1.process(State.scala:184)
at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:98)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.MainLoop$.next(MainLoop.scala:98)
at sbt.MainLoop$.run(MainLoop.scala:91)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:70)
at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:65)
at sbt.Using.apply(Using.scala:24)
at sbt.MainLoop$.runWithNewLog(MainLoop.scala:65)
at sbt.MainLoop$.runAndClearLast(MainLoop.scala:48)
at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:32)
at sbt.MainLoop$.runLogged(MainLoop.scala:24)
at sbt.StandardMain$.runManaged(Main.scala:53)
at sbt.xMain.run(Main.scala:28)
at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
at xsbt.boot.Launch$.withContextLoader(Launch.scala:129)
at xsbt.boot.Launch$.run(Launch.scala:109)
at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:36)
at xsbt.boot.Launch$.launch(Launch.scala:117)
at xsbt.boot.Launch$.apply(Launch.scala:19)
at xsbt.boot.Boot$.runImpl(Boot.scala:44)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)
[error] sbt.compiler.EvalException: Type error in expression
[error] Use 'last' for the full log.

my build.sbt looks like this:
import sbt.Keys._

name := "bi-data-generator"

val commonSettings = Seq(
version := "1.0",
scalaVersion := "2.11.7",
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
)

lazy val activeSlick = project.in(file("active-slick")).settings(commonSettings:_*)
lazy val root = (project.in(file("."))).dependsOn(activeSlick)

libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.1.0",
"com.typesafe.slick" %% "slick-codegen" % "3.1.0",
//use ActiveSlick for generic DAOs
//"io.strongtyped" %% "active-slick" % "0.3.3",

"org.postgresql" % "postgresql" % "9.4-1204-jdbc41",
//for hikari: do not use HikariCP (only for Java 8) instead use HikariCP-java6
//it also supports JDK7 otherwise the is an unsupported version error
//"com.zaxxer" % "HikariCP-java6" % "2.3.12",
"com.zaxxer" % "HikariCP" % "2.4.2",
"com.typesafe.slick" % "slick-hikaricp_2.11" % "3.1.0",

"ch.qos.logback" % "logback-classic" % "1.1.3",

"org.scalatest" %% "scalatest" % "2.2.4" % "test",

//Gaussian libraries
// other dependencies here
"org.scalanlp" %% "breeze" % "0.10",
// native libraries are not included by default. add this if you want them (as of 0.7)
// native libraries greatly improve performance, but increase jar sizes.
"org.scalanlp" %% "breeze-natives" % "0.10"
)

slick <<= slickCodeGenTask

sourceGenerators in Compile <+= slickCodeGenTask

lazy val slick = TaskKeySeq[File]
lazy val slickCodeGenTask = (sourceManaged, dependencyClasspath in Compile, runner in Compile, streams) map { (dir, cp, r, s) =>
val outputDir = (dir / "main/slick").getPath
val username = "postgres"
val password = "postgres"
val url = "jdbc:postgresql://127.0.0.1/Artificial"
val jdbcDriver = "org.postgresql.Driver"
val slickDriver = "slick.driver.PostgresDriver"
val pkg = "bi.models"
toError(r.run("slick.codegen.SourceCodeGenerator", cp.files, Array(slickDriver, jdbcDriver, url, outputDir, pkg, username, password), s.log))
val fname = outputDir + "/" + "bi/models" + "/Tables.scala"
Seq(file(fname))
}

Cheers, Tai

@octonato
Copy link
Contributor

Hi @taitruong,

Sorry for my late reply. I was abroad and not having much time to sit in front of my computer.

I never tried to include active-slick as a submodule. It's possible that our sbt is configured in a way that make it difficult (or impossible) to include it as a submodule.

I suggest you to check out active-slick and build and publish it locally to your ivy repo.

Please, let me know your findings.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants