-
Hi, I'm struggling to find a good solution to share the models between my frontend (outwatch using scalajs) and my backend (play framework 3.0.5) using (of course) scalasql (version 0.1.11). The problem is that I can't use the scalasql import in my frontend code, so I can't define the case class and object in the shared module. I've now just duplicated the models in my frontend src tree and backend src tree. I don't see an obvious way to avoid duplication, has anyone found a proper solution for this? Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Ok, with the help of a little AI, I've figured out that you can in fact have a JVM and a JS part in the shared section, so building on that I managed to solve it. If anyone has other suggestions for different solutions or improvements to the solution below, they would still be welcome. Here is what I did: I've got a server, client and shared project in my build.sbt: lazy val server = (project in file("server"))
.settings(commonSettings)
... etc.
lazy val client = (project in file("client"))
.settings(commonSettings)
... etc.
lazy val shared = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("shared"))
.settings(commonSettings)
.settings(
libraryDependencies ++= Seq(
"com.typesafe.play" %%% "play-json" % playJsonVersion,
"com.lihaoyi" %%% "upickle" % "4.0.0"
)
)
.jvmSettings(
libraryDependencies ++= Seq(
"com.lihaoyi" %% "scalasql" % scalasqlVersion
)
)
.jsConfigure(_.enablePlugins(ScalaJSWeb)) So the key here is to use:
|
Beta Was this translation helpful? Give feedback.
-
One thing I would try is to have only the data objects (the "row" case classes) in the shared project, and keep the tables in the server/jvm project. |
Beta Was this translation helpful? Give feedback.
Ok, with the help of a little AI, I've figured out that you can in fact have a JVM and a JS part in the shared section, so building on that I managed to solve it.
If anyone has other suggestions for different solutions or improvements to the solution below, they would still be welcome.
Here is what I did:
I've got a server, client and shared project in my build.sbt: