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 -~----------~----~----~----~------~----~------~--~---