On Wednesday, August 24, 2016 at 3:59:46 PM UTC-7, Adam G wrote: > > I have a model that is writing unix timestamps to PG as an integer. I'd > like to work with Time (or DateTime) objects when interfacing with the > model in code. Is there a recommend way to have the model automatically > convert those integers to time objects when reading from the database? >
The recommended way would be to use a timestamp column in the database. However, since you appear to not want to do that, the serialization plugin is probably your best bet: class Foo < Sequel::Model plugin :serialization serialize_attributes [lambda(&:to_i), Time.method(:at)], :timestamp_column end Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
