Play Framework and Slick project architecture - scala

I'm migrating an Application from Grails to Play Framework and i'm currently trying to figure out what's the best way of organizing the project structure.
I want to use Slick Codegen alongside with Flyway for Migrations, cause i want to keep a track of all the migrations that are being done (a solution similar to Rails Migrations would be perfect).
I see that Play Framework has the Play-Slick module but from what i've noticed, everything just happens like pure black-magic.
I saw an example on GitHub where Slick Modelling, Play Framework and Flyway Migrations are 3 separate SBT Modules, which makes perfect sense in case we ever want to move away from Play Framework.
Now, my questions is: What's the best architecture approach for a Play Framework App?
Note: I'm a newbie in Play Framework and Scala.

I did a post a while ago about using Play + slick + mysql. Is has the minimal structure to work, but the one I found more correct (I think this point will be subjective): http://pedrorijo.com/blog/play-slick/
or the source code at https://github.com/pedrorijo91/play-slick3-steps

Related

Can't get Blazor project running with Entity Framework

I'm trying to create a simple Blazor client server app using EF, similar to this article.
So I've got a client, server, and common libraries, and this worked fine. But then I added the EF component to the common library, so that I could use real data from my database, instead of toy data from the demo.
I tried making them all Core 3.0, but this doesn't work because Blazor seems to require .NET Standard 2.0. Without that, I get all kinds of errors.
But then the common library can't use EF, because (if I'm reading this right) EF6 isn't supported on Standard 2.0. If I try, I again get tons of errors.
So I'm not sure, but I can't find any scenario that would allow me to share EF objects between client and server--which is a major rationale for Blazor.
Is there some other way to accomplish this?
The shared library should not use or reference EF.
Add EF to the Server project only and make the data available through an API controller.
You should make the common project netstandard and use EF core (not EF 6)

Slick and Anorm in Typesafe Platform

I've started using Scala, Play Framework and currently I'm discovering other technologies from Typesafe Reactive Platform. However, I'm just little bit confused about persistence layer technology which to use. There is Anorm from Play Framework, which is part of the Reactive platform, and Slick, which is part of the platform too. Are there any future plans to prefer one of them in the whole platform (for example to leave Anorm and recommend Slick as major Scala DB technology in Play)? Is it possible to say that one of them is currently under more active development, with brighter future? Or is there any recommendation by Typesafe which one to use with the Typesafe Reactive Platform?
Thank you.
This is rather a subjective question, but some objective data can be found:
anorm has recently been moved out from the main Play Framework github repository
Slick is a more recent project
it has been said that PlayFramework is planned to move to Slick in the future (source: slide 20 of http://slick.typesafe.com/talks/2012-10-17_Typesafe-Slick-presentation-at-BASE/2012-10-17_Typesafe-Slick-presentation-at-BASE.pdf)
Slick will be official database connector in
Play / Typesafe Stack
That being said, they have a different approaches. Anorm is agnostic about the underlying database and it only provides a nicer way to write SQL queries; on the other hand, Slick is db specific and it provides a scala-like syntax for queries.
Personal opinion
I've been actively working on SQL projects in scala over the last two years and my team has moved from Anorm to Slick for new projects. We're also considering moving from Anorm to Slick in existing code bases.
Part of the reasons come from personal taste, and part from the objective data above, that make me think Anorm will be progressively discontinued.

CRUD operations on a database in Play

I'd like to be able to create/delete/change a database and tables, create/delete indexes and all these kinds of things by Scala code, not by an sql file. Probably, using anorm. Is wonder, is it possible?
I know it's possible to do CRUD operations with tables.
Slick is a Scala ORM that can do most of what you're asking for, however it does not have a pure Scala way of creating a new database. You can read more about that here.
You say you are using play then start off using Ebean ORM
Have a look at
Play Persistance
and
Avaje EBean
If you have downloaded play look in the samples directory there is a computer database example. It is a very good example of CRUD
Good luck
I would recommend slick! Slick at first seems different if you are moving from directly stating your statements, but it is super handy to work with. Check it out here

Scaffolding for Play Framework 2

Is there scaffolding generator utility for Play Framework 2 for Scala like Ruby on Rails has? I found some topics about this but didn't figure out which one was most popular or even if there was the standard one?
Your thoughts?
UPDATE: I mean scaffolding for generating controllers, views, models or any of them.
If you're using MongoDB, the reactive mongo plugin has an auto source feature, which gives you a REST scaffolding API:
http://mandubian.com/2013/06/11/play-autosource/
Slick can generate models from your database tables. They aren't play specific so I think you'd have to write controllers yourself, but it's a start.
https://scala-slick.org/

Should I use MongoDb module or morphia module or Casbah in play framework for MongoDb?

I am working on a play framework project with scala in which I want to have Scala domain classes (or even Java domain classes) using MongoDb as data store.
I want maximum performance while serving hundreds of thousands if not millions of requests per day.
Since both scala language and Play framework is adding new features by the month, what is the best answer in terms of latest production version of the modules mentioned in the question
and play framework 1.2.2, scala 0.9.1+ and scala language 2.8+?
for anyone stumbling upon this question and using playframwork 2.1.x or above I highly recommend taking a look at reactivemongo site and github project.
It's a mongodb scala driver that allows asynchronous db operations.
Great performance and mature enough for use in production.
At the time of writing this the current version is 0.9 and is being used by us in production without any problems.
I use Morphia module, a MongoDB integration for Play! 1.2.x
For scala I would suggest you have a look at https://github.com/novus/salat
I've written a play plugin for salat which you can find here https://github.com/leon/play-salat
Good luck!