Holy shit, I had no idea DBIx::Class could do this! I'm integrating Calibre's SQ...
Richard "mtfnpy" Harman (he/him) @xabean@infosec.exchange
Holy shit, I had no idea DBIx::Class could do this!
I'm integrating Calibre's SQLite database into my DIY #Nook cloud service and of course Calibre's got ISO8601 format YYYY-MM-DD HH:MM:SS.NNNN+00:00 dates, and the Nook cloud protocol wants unix epoch timestamps.
I was already aware SQLite had the unixepoch() function to translate a datetime into an epoch, but ... this is beautiful:
$books = $calibre->resultset("Book")->search({},
{
'+select' => [ { '1000*unixepoch' => 'me.pubdate' } ],
'+as' => [ qw( pubdate ) ],
}
);
This transparently up-converts the datetime into a nanosecond epoch at query time, and overlays the converted value into the original accessor method for the table column. So later as I loop over books in the resultset, $book->pubdate is just magically the epoch timestamp. Lovely.