I would like to know if here is any library that I could use to do asynchronous database calls? I'm using PostgreSQL as my database. I came to know about slick. Is that non-blocking? Any suggestions?
From Slick documentation What is Slick?
Execution of database actions is done asynchronously, making Slick a perfect fit for your reactive applications based on Play and Akka.
In addition to Slick as mentioned by #Jean there is also ScalikeJDBC-async build on top of postgresql-async.
Related
I'm new in Slick and Play and I can't find any references about caching in docs(2 and 3rc). Is there any native way in Slick for cache organization or if not tell me, please, why and whats the reasons for not having it? Summary, I hope that somebody help me in this question or show another better way.
I don't think Slick has got anything, it is just for interacting with a RDBMS. But since you are using play framework you have the play cache API:s that you can use, for example in a DAO that wraps Slick. You can read more about it in the play framework docs here: https://www.playframework.com/documentation/2.3.x/ScalaCache
Also see http://slick.typesafe.com/doc/2.1.0/orm-to-slick.html#read-caching and the following section
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.
I am new in play framework 2.
I have play 2 with scala and MongoDb requirement.
I searched lots on Play 2 and MongoDb connection, but didn't find any useful documentation.
There is lots of plugins available eg. Casbah, Reactive Mongo, Salat. So which is best for use, and which have better future?
If i want to implement my own connection to Mongo without using third party plugin, is it possible?
Please give examples and document on Play 2 and MongoDB connection.
I suggest using ReactiveMongo as its non-blocking approach is similar to how Play itself works. The API works with scala Futures which is a a really nice fit with Play's Async actions. You can also use their macros to convert case classes straight to BSON sparing quite some boilerplate code.
A lot of time has passed but I would like to share an update for those, who may search for Scala MongoDB client library for Play Framework.
Reactive Mongo is great but still lacks Play Framework 2.4 integration and MongoDB 3.0. We have waited for a long time thus wrote a library that wraps original MongodDB client in the Scala style way and is similar to Reactive Mongo in the api. Take a look at https://github.com/evojam/play-mongodb-driver. With the Play Framework module it's pretty straightforward to start, like few minutes to get working code.
This way MongoDB is nice and easy to use in Scala. We have provided a comparison of the sample query execution is in our blog post about the driver on site.
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
I want to do an application in Scala, with a MongoDB database. I found some tutorials to use it with ReactiveMongo, I wrote my classes, but I want to test it and I don't understand how to do a simple request; to add a user for example, or find him.
What is the right method to use?
You could use the Activate framework. It supports ReactiveMongo with a simple usage interface for queries and modifications.
Using it, is also easy to switch to other types of databases, like postgre and mysql.
http://activate-framework.org/
It uses transparent persistence with efficient memory usage, providing a simpler persistence paradigm with high scalability. Take a look at http://databen.ch
Do you want ReactiveMongo or just want to use mongodb on scala. If it's the lastest, try http://mongodb.github.io/casbah/tutorial.html
Is what we use in our projects...