Can Perl DBIx :: Class override the way a column is retrieved from a database?

I have never used DBIx :: Class until today, so I am completely new to it.

I'm not sure if this is possible or not, but basically I have a table in my SQLite database that has a timestamp column in it. The default value for the timestamp column is "CURRENT_TIMESTAMP". SQLite stores this in the GMT time zone, but my server is in the time zone of the CDT.

My SQLite query to get the timestamp in the correct time zone:

select datetime(timestamp, 'localtime') from mytable where id=1; 

I am wondering if it is possible in my DBIx schema for "MyTable" to force it to use the datetime function each time it retrieves the "timestamp" field from the database?

In the cookbook, it looks like this can be done using the function → search (), but I'm wondering if it is possible to do this if I use the search functions (), find (), all (), find_or_new () or any function that pulls out this column is from the database, will the SQLite datetime () function be applied to it?

DBIx :: The class seems to have a lot of documentation - I think I'm just so new to this. I do not find the right places / things to search.

Thanks in advance!

+4
source share
1 answer

I used InflateColumn :: DateTime in this way and with a timestamp, and I can confirm that it works, but I am wondering if you have it back.

If your column is in UTC, check the UTC column and then it will be UTC time when loading it. Then, when you set_timezone to DateTime (presumably this will be a release issue - on an output that you care about locally) you can set it at local time and it will make the necessary settings.

+2
source

Source: https://habr.com/ru/post/1303699/


All Articles