Hey
In my Hanami 2 project, Iām using postgreSql and want timestamps returned in a specific time zone (Europe/Vienna
), not UTC. A postgreSql-server is set to UTC by default, which makes sense, cause it is future proof. So I want to let it untouched. postgreSql handles this perfectly with timestamptz
, but you need to set the time zone for each DB connection using SET TIME ZONE
.
To make that work in Hanami, you have to customize the db provider.
# frozen_string_literal: true
Hanami.app.configure_provider :db do
config.gateway :default do |gw|
gw.connection_options after_connect: proc { |conn| conn.exec("SET TIME ZONE 'Europe/Vienna'") }
end
end
So my question:
Should this use case be supported out of the box without custom after_connect
config?
How do you deal with this? I believe that this use-case occurs most of the time, or am I wrong?
The downside:
This approach relies on postgreSqls timestamptz
behavior and SET TIME ZONE
, which may not be portable to other databases.
Thanks