Chapter 10. Persistence with Mapper

 

This chapter covers

  • Connecting to a database
  • Query constructs
  • Relationships
  • Entity validation

The vast majority of web applications that do anything semiuseful will ultimately need to store their data somewhere. Over the past decade or more, the relational database management system (RDBMS) has been the solution of choice for most developers, and the ANSI Structured Query Language (SQL) has become a standardized dialect for interacting with these databases. Although many database vendors have added and extended the ANSI version of SQL in several different directions, the core operations are still pretty much the same in any engine you choose to work with.

In the beginning, developers would construct their SQL statements as strings in their application code and then ultimately pass that to a database driver for execution. This approach worked fine and was used by many, many applications. But as time progressed and the object-oriented (OO) revolution took hold, there was a desire to interact with the underlying data store in a more OO manner. At this point, object-relational mapping (ORM) systems were born.

Today, you can find ORM implementations in nearly every programming language, and they often take different forms and routes of design. In this regard, both Scala and Lift are no different. The Scala ecosystem has numerous ORM-style interfaces to SQL stores, and Lift provides two implementations: Mapper and its younger brother Record.

10.1. Setting up a database

10.2. Interacting with Mapper

10.3. Advanced Mapper

10.4. Summary