Skip to content

Instantly share code, notes, and snippets.

@dragisak
Created February 11, 2013 18:17
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragisak/4756344 to your computer and use it in GitHub Desktop.
Save dragisak/4756344 to your computer and use it in GitHub Desktop.
Joda DateTime mapper in Slick
import slick.lifted.MappedTypeMapper
import java.sql.Date
import org.joda.time.DateTime
import slick.lifted.TypeMapper.DateTypeMapper
object DateTimeMapper {
implicit def date2dateTime = MappedTypeMapper.base[DateTime, Date] (
dateTime => new Date(dateTime.getMillis),
date => new DateTime(date)
)
}
@dragisak
Copy link
Author

To use just:

import DateTimeMapper._

@sumew
Copy link

sumew commented Mar 2, 2013

Thanks, this is handy!

@paulcoghlan
Copy link

Hi,

I think MappedColumnType is used in Slick 2.1.0, so this becomes:

  implicit def dateTime  =
      MappedColumnType.base[DateTime, Timestamp](
        dt => new Timestamp(dt.getMillis),
        ts => new DateTime(ts.getTime)
  )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment