Maybe I'm misunderstanding what you're attempting here, but I don't think
that this will work. The major roadblock I see is that the SQL query strings
are tied directly to a table name (e.g. "User.createdAt"), and therefore to
a particular type. Off the top of my head, I think that you *could* write
something that would be templated by leveraging base Mapper traits instead.
Something maybe like:

def DateRangeParam[O](field: MappedField[T, O], startDate : Box[Date],
endDate: Box[Date]) : QueryParam[O] =
  (startDate, endDate) match {
    case (Full(start), Full(end)) =>
BySql(field.fieldOwner.getSingleton.dbTableName + "." + field.dbColumnName +
" between ? and ?", ...

and so on. I have no idea if this will really work, since I shoot myself in
the foot with the type system all of the time, but it should be possible to
dynamically build the query string based on the field and mapper class
involved.

Derek

On Mon, Jul 6, 2009 at 1:56 PM, Dano <olearydani...@gmail.com> wrote:

>
> Hello Lifters!
>
> I recently acquired the Lift  book and saw a neat example of how to
> use a QueryParam() to setup a query which does date range checking.
> The code I am referencing is the dateClause expression in the
> Expense.scala file (pocketchange project).  It looks like:
>
>    val dateClause : QueryParam[Expense] = (startDate,endDate) match {
>      case (Full(start), Full(end)) => BySql("Expense.dateOf between ?
> and ?",
>
> IHaveValidatedThisSQL("dchenbecker", "2009-02-22"),
>                                             start, end)
>      case (Full(start), Empty) => BySql("Expense.dateOf >= ?",
>
> IHaveValidatedThisSQL("dchenbecker", "2009-02-22"),
>                                         start)
>      case (Empty, Full(end)) => BySql("Expense.dateOf <= ?",
>                                       IHaveValidatedThisSQL("dchenbecker",
> "2009-02-22"),
>                                       end)
>      case _ => new Ignore[Expense]
>    }
>
> I want to use this clause across a set of Mapper classes and so I
> thought I would take the code and try to parameterize it with a type
> so that I could pass in a Mapper class at the type.
>
> I have tried to model the type as both KeyedMapper and Mapper to no
> avail (see broken code below)  I am stumbling on the User class which
> is probably the most involved of the Mapper classes I need to get to
> work.
>
> Does anyone have a quick pointer for a type challenged lifter?
>
> Thanks in advance.
>
>
> Dano
>
>    /* Site analytics code */
>    val startDate: Box[Date] = parseDate("2009/06/01 00:00")
>    val endDate: Box[Date] = parseDate("2009/07/01 00:00")
>    val users = User.findAll(dateClause(startDate, endDate, User))
>    println("users = " + users)
>
>  private def dateClause[T <: Mapper[Long]](startDate: Box[Date],
> endDate: Box[Date], tbl: T) : QueryParam[T] = (startDate,endDate)
> match {
>      case (Full(start), Full(end)) => BySql("User.createdAt between ?
> and ?",
>                                             IHaveValidatedThisSQL("djo",
> "2009-06-22"),
>                                             start, end)
>      case (Full(start), Empty) => BySql("User.createdAt >= ?",
>                                         IHaveValidatedThisSQL("djo",
> "2009-06-22"),
>                                         start)
>      case (Empty, Full(end)) => BySql("User.createdAt <= ?",
>                                       IHaveValidatedThisSQL("djo",
> "2009-06-22"),
>                                       end)
>      case _ => new Ignore[T]
>  }
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@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