Created
February 11, 2013 18:17
-
-
Save dragisak/4756344 to your computer and use it in GitHub Desktop.
Joda DateTime mapper in Slick
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
) | |
} |
Thanks, this is handy!
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
To use just:
import DateTimeMapper._