search
top

Slick: Persistence with Style

What is Slick?
Slick is a Functional Relational Mapper (FRM as oppose to the commonly used ORM) that allows us to compose type-safe database queries. Slick also allows us to interact with our database in the same way we would with a Scala collection; so no more raw SQL.

What's most important though, is that execution of our queries on our database is done asynchronously. This makes Slick a perfect fit for our Akka server.

Does Slick play well with PostgreSQL?
Yes. Slick supports a multitude of relational database management systems; but I prefer to work with PostgreSQL because it's open-source.

Slick in action
In my previous journal entry we saw our LoginHandler actor handle incoming messages and use a UserDAO object to do look ups and process user registrations. Let's take a closer look at our UserDAO class.

Here we can see the find by email method I was using in LoginHandler to provide a user for user authentication.

This method is non-blocking and promises a Future[Option[User]]. Our User is a Scala case class and looks like:

We now have a basic skeleton for processing messages from the client that can persist data to the database when needed. From this point on we'll be adding more logic to handle more game features and also introduce Actors, DAOs, and domain models where needed to flesh out the full game server.

Leave a Reply

Captcha image


top