Lift Web Framework

Lift allows you to create model objects that map themselves to and from the database. Here's an example of a "User" model object.

There are 325722 records in the "Person" table. The first one is Person={ firstName= vc lastName=vcxcvc personalityType=ENTJ  }. Press to create more records.

/**
 * The singleton that has methods for accessing the database
 */
object User extends User with KeyedMetaMapper[Long, User] {
  override def dbTableName = "users" // define the DB table name

  // define the order fields will appear in forms and output
  override lazy val fieldOrder = List(id, firstName, lastName, 
                                      email, password, textArea)
}

/**
 * An O-R mapped "User" class that includes first name, last name,
 * password and we add a "Personal Essay" to it
 */
class User extends ProtoUser[User] {
  def getSingleton = User

  // define an additional field for a personal essay
  object textArea extends MappedTextarea(this, 2048) {
    override def textareaRows  = 10
    override def textareaCols = 50
    override def displayName = "Personal Essay"
  }
}

For this little bit of work, we get a complete user with first name, last name, password, email, and a personal essay. Each of the fields knows how to validate itself. The User (and any other "Mapped" class) knows how to Create, Update, Read, and Delete itself from the database. It knows how to convert itself to a string, to XML, and even generate HTML forms for itself.


Lift is Copyright 2007-2010 WorldWide Conferencing, LLC. Distributed under an Apache 2.0 License.
Lift version 2.3 built on Tue Apr 05 13:24:00 PDT 2011.
Stats: Total Memory: 532,938,752 Free Memory: 489,569,104 Open Sessions: 97
Updated At: Wed May 16 20:23:15 PDT 2012 Started At: Mon Mar 26 20:25:42 PDT 2012