As I was flushing out some tests for my RSS reader, and I realized I had not really thought through my update interval settings for feeds. I had used an interval data type, and I run a postgresql database on my server, but a sqlite db when I’m doing things locally. I also haven’t even started on my daemon to do updates; I’ve just cron'ed things for now. So I haven’t really used the field but I’m still planning to once I flush out the update daemon. Since I’m writing tests I might as well address the issue.

The issue was that I didn’t really pay homage to SQLite’s type system. My ‘interval’ typed column in sqlite is using the text storage class. I don’t really want focus my time on tackling formatting/parsing issues, and I like being able to use multiple databases. For columns with date types, I’m just using DBIx::Class::InflateColumn::DateTime, so I was happy to see that there was an InflateColumn for Durations also DBIx::Class::InflateColumn::DateTime::Duration. I soon found out that things were not as simple with InflateColumn::Datetime::Duration (ICDD). Unlike ICD, you need to mark each column with a ‘is_duration’ attribute in your schema files. I’ve been in the mode of using dbicdump to write out my schemas, so that wasn’t going to work. Plus ICD picked up things automatically for datetime fields, why couldn’t ICDD do the dame with interval fields? It turns out it can, it’s an easy 1 line change. When peering into the code though, I noticed that the parser/formatter was hard coded. This was getting to be a bit more than I wanted to tackle at the moment, so I’ve published the simple change to github. I think I want to see if I can get it to be a bit more flexible with the parser it’s using before I circle back and see if anyone else likes the changes, or if I should just find a new namespace for the module. So back to integrating ICDD, I just need to adjust my format to match ICDD’s hard coded one. Turns out that it isn’t too bad either, a simple command to run on connection in my DB config file:

1
2
3
4
5
6
7
8
9
# connection string
<connect_info>
  dsn     dbi:Pg:database=rss
  user    rss
  pass    passwordgoeshere
  <extra>
    on_connect_do =  set intervalstyle='iso_8601';
  </extra>
</connect_info>

and a quick addition to the connection:

1
  $schema = mRSS::Schema->connect( $dsn, $user, $pass, $options, $extra);

I add ICDD to my loader_options components, rerun dbicdump, and presto.. I’m getting back DateTime::Duration objects from that field.

Now back to tests.