Here is what you need for a minimal Person table that contains two
columns: an id for the primary key, and name which is a string:

package com.jacksdomain.model

import net.liftweb.mapper._

class Person extends LongKeyedMapper[Person] with IdPK {
  def getSingleton = Person

  object name extends MappedString(this, 100)
}

object Person extends Person with LongKeyedMetaMapper[Person] {
  override def dbTableName = "person"
}

You can then do things like this:

val person = Person.find(1)   // retrieve the person with id = 1 from
the database
val person = Person.find(By(Person.name, "Jack")) // retrieve the
person with name = "Jack" from the database
val people = Person.findAll() // retrieve all people form the database
val people = Person.findAll(By_<(Person.id, 10)) // retrieve all the
people with id < 10

etc.

-harryh

On Nov 26, 1:39 pm, jack <jack.wid...@gmail.com> wrote:
> wow. thats impressive. But for this, what does the Person class have
> to look like? Suppose I have the table but I don't have the Person
> class written. What does it need to look like?
>
> On Nov 26, 1:32 pm, harryh <har...@gmail.com> wrote:
>
> > val people = Person.findAll()
>
> > On Nov 26, 1:22 pm, jack <jack.wid...@gmail.com> wrote:
>
> > > I have my database configured properly in Boot.scala and in my
> > > pom.xml. Suppose I have a table name person with a field called name.
> > > What is the simple code to return all rows of this table using Mapper.
> > > I want to understand the essence of how lift ties tables to objects
> > > with a simple example.

--

You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to 
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en.


Reply via email to