To answer my own question: I'm pretty sure this isn't possible at present, because there doesn't seem to be a way to register your own instances of PrimitiveJdbcMapper without modifying Squeryl.
For now, I'm making do with a NonPrimitiveJdbcMapper which relies on SquerylEntryPoint.sqlDateTEF (and thus on java.sql.Date, unfortunately).
I don't have time to change Squeryl right now, but if someone wants to try it sometime, you could try adding this (warning: completely untested) code to org.squeryl.internals.FieldMapper:
implicit val localDateTEF =
// new TypedExpressionFactory[LocalDate,TDate] with PrimitiveJdbcMapper[LocalDate] {
new TypedExpressionFactory[LocalDate,LocalDate] with PrimitiveJdbcMapper[LocalDate] {
val sample = LocalDate.now()
val defaultColumnLength = -1
def extractNativeJdbcValue(rs: ResultSet, i: Int) = rs.getObject(i, classOf[LocalDate])
}
implicit val optionLocalDateTEF =
// new TypedExpressionFactory[Option[LocalDate],TOptionDate] with DeOptionizer[LocalDate, LocalDate, TDate, Option[LocalDate], TOptionDate] {
new TypedExpressionFactory[Option[LocalDate],TOptionDate] with DeOptionizer[LocalDate, LocalDate, LocalDate, Option[LocalDate], TOptionDate] {
val deOptionizer = localDateTEF
}
implicit val localDateTimeTEF =
new TypedExpressionFactory[LocalDateTime,TTimestamp] with PrimitiveJdbcMapper[LocalDateTime] {
val sample = LocalDateTime.now()
val defaultColumnLength = -1
def extractNativeJdbcValue(rs: ResultSet, i: Int) = rs.getObject(i, classOf[LocalDateTime])
}
implicit val optionLocalDateTimeTEF =
new TypedExpressionFactory[Option[LocalDateTime],TOptionTimestamp] with DeOptionizer[LocalDateTime, LocalDateTime, TTimestamp, Option[LocalDateTime], TOptionTimestamp] {
val deOptionizer = localDateTimeTEF
}
implicit val zonedDateTimeTEF =
new TypedExpressionFactory[ZonedDateTime,TTimestamp] with PrimitiveJdbcMapper[ZonedDateTime] {
val sample = ZonedDateTime.now(ZoneOffset.UTC)
val defaultColumnLength = -1
def extractNativeJdbcValue(rs: ResultSet, i: Int) = rs.getObject(i, classOf[ZonedDateTime])
}
implicit val optionZonedDateTimeTEF =
new TypedExpressionFactory[Option[ZonedDateTime],TOptionTimestamp] with DeOptionizer[ZonedDateTime, ZonedDateTime, TTimestamp, Option[ZonedDateTime], TOptionTimestamp] {
val deOptionizer = zonedDateTimeTEF
}
You could add the TEFs above to org.squeryl.internals.FieldMapper.PrimitiveTypeSupport, and change FieldMapper.initialize method to call "register" for each of the TEF instances above. Come to think of it, for consistency the implicit vals and defs above should probably not be implicits, but should be redeclared as implicits in
PrimitiveTypeMode, similar to implicit val sqlDateTEF = PrimitiveTypeSupport.sqlDateTEF and implicit def dateToTE(s: Date) = dateTEF.create(s).