← Learning

Postgres Module

NOTE

The Postgres module is deprecated and is primarily left up as an additional resource. While the basic knowledge presented in the reading section will be valuable, the example and milestone project use a library that is being phased out within our group. New Postgres knowledge will primarily be learned as you use the tools you need in your production team.

What is Postgres?

Postgres is a database management system developed by the computer science department at the University of California Berkeley. Since its original release, Postgres has evolved into PostgreSQL which is an open source project that complies with many SQL standards. So why would someone use Postgres instead of writing their own server in Scala? The answer lies in how Postgres works. When you try to perform an operation, also known as a transaction, on a database it is guaranteed to not be affected by other operations happening concurrently which means each operation has its own view of the data.

How can Postgres be used with Scala?

The library we use to interact with Postgres databases from Scala is Squeryl. It supports multiple database management systems, but uses syntax similar to the console commands PostgreSQL provides.

Reading

Before you begin writing full code, please read through parts I and II of the PostgreSQL documentation and all of the Squeryl documentation. The postgres reading can get kind of long so you could break it up a bit, and possibly learn better, by trying out some of the concepts it introduces.

Example

Once you have completed all the reading, follow the email database example contained in this module. It will walk you through setting up a database on your local machine and accessing it through Squeryl.

Milestone Project

Take your existing Milestone Project from the Scala and Akka modules and port the storage to use Postgres. Now if your system is taken down for any reason, you should be able to restart it and keep all articles you stored before it went down.