Overriding column type

8 views
Skip to first unread message

Richard Rodseth

unread,
May 21, 2016, 1:48:44 PM5/21/16
to scala...@googlegroups.com
I'm really hoping someone can help me with this. I have timestamps in Postgres stored as timestamp without timezone and need to treat them as UTC. I don't really care if I make the column type Timestamp or Instant or Long or TimestampUTC extends AnyVal except that I haven't been able to figure out how to add <= to queries when I use custom types.

But one way or another I will need access to the ResultSet so I can call getTimestamp passing in a Calendar. 

I've resorted to trying to implement ColumnType[Instant] by piecing together all the needed pieces by looking at JdbcTypesComponent and slick-pg. 

  implicit val utcInstantMapping = new ColumnType[Instant] {

...

    def getValue(r: java.sql.ResultSet, idx: Int): java.time.Instant = {

      val ts = r.getTimestamp(idx, utcCalendar)

      val result = Instant.ofEpochMilli(ts.getTime)

       result

   }

}


The getValue method got called for a column designated as Instant. But as I mentioned, I can't figure out how to get the query support for inequalities.

So I thought maybe I could just "override" the mapping for Timestamp, but how does one do that?

Any pointers would be much appreciated.




Richard Rodseth

unread,
May 23, 2016, 12:51:25 AM5/23/16
to scala...@googlegroups.com
I ended up modeling my solution on the structure of

and an AnyVal called TimestampUTC
Reply all
Reply to author
Forward
0 new messages