The desired query can be produced using a custom function mapping:
class DateTrunc(span: String,
e: DateExpression[Timestamp],
m: OutMapper[Timestamp])
extends FunctionNode[Timestamp]("date_trunc",
Some(m),
Seq(new TokenExpressionNode("'"+span+"'"), e))
with DateExpression[Timestamp]
def dateTrunc(span: String,
e: DateExpression[Timestamp])
(implicit m: OutMapper[Timestamp]) = new DateTrunc(span,e,m)
This can then be used in the actual query, e.g.:
def historyQuery(name: String,
span: String = "day",
pageSize: Int = 10) = from(table) (
stats =>
where(stats.name === name)
groupBy(dateTrunc(span,stats.datetime))
compute(count)
orderBy(dateTrunc(span,stats.datetime) desc)
) page(0,pageSize)