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.
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.
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 )
Create a new file named
Contact.scala
inside themodel
package, with the following code snippet:package code.model import net.liftweb.squerylrecord.KeyedRecord import net.liftweb.squerylrecord.RecordTypeMode._ import net.liftweb.record.{MetaRecord, Record} import net.liftweb.record.field._ import org.squeryl.annotations.Column class...