O'Reilly logo

Lift Application Development Cookbook by Gilberto T. Garcia Jr.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Mapping a table to a Scala class

Now that we have learned how to create a connection to the database using Squeryl and Record, it is time to learn how to map database tables to Scala classes.

Getting ready

Since the project from the previous recipe has the connection already configured, we are going to use it. If for any reason you didn't have the connection to the database configured, please follow the Configuring a connection to a database using Squeryl recipe in this chapter.

How to do it...

  1. Create a table named contacts in the database using the following SQL code snippet:
    create table contacts (
      id serial not null primary key,
      name varchar(100) not null
    )
  2. Create a new file named Contact.scala inside the model package, with the following code snippet: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required