On Monday, May 18, 2020 at 11:22:32 AM UTC-7, Tiago Cardoso wrote:
>
> I'm having a small integration issue with rodauth-rails, sequel and the
> sequel-activerecord-connnection gem, when performing date operations.
>
> My issue is a particular query where I do:
>
> .where(Sequel[oauth_grants_expires_in_column] >= Sequel::CURRENT_TIMESTAMP)
>
>
> The main problem is that, when using plain sequel, datetimes are stored in
> localtime, while in rails, they're converted to utc and stored. In itself,
> this shouldn't be a problem, however, the resulting query from the abovet
> subset is:
>
> AND (`expires_in` >= datetime(CURRENT_TIMESTAMP, 'localtime')))
>
This issue is limited to SQLite, correct? You can override
Dataset#constant_sql_append to change things to use utc instead of local:
DB.extend_datasets do
def constant_sql_append(sql, constant)
case constant
when Sequel::CURRENT_TIMESTAMP
sql << "CURRENT_TIMESTAMP"
else
super
end
end
end
It's possible we could modify the sqlite support in Sequel to make the
timezone passed to the datetime function configurable. I'll see about
doing that in the next release.
There's a good reason for the current default behavior, and that is that
otherwise, DB.get(Sequel::CURRENT_TIMESTAMP.as(:v)) would return a wrong
timestamp if the local timezone is not UTC:
irb(main):001:0> DB.get(Sequel::CURRENT_TIMESTAMP.as(:v))
I, [2020-05-18T12:20:59.020968 #85115] INFO -- : (0.001044s) SELECT
datetime(CURRENT_TIMESTAMP, 'localtime') AS 'v' LIMIT 1
=> "2020-05-18 12:20:59"
irb(main):002:0> DB.get(Sequel.lit 'CURRENT_TIMESTAMP')
I, [2020-05-18T12:21:14.130685 #85115] INFO -- : (0.000181s) SELECT
CURRENT_TIMESTAMP LIMIT 1
=> "2020-05-18 19:21:14"
irb(main):003:0> Time.now
=> 2020-05-18 12:22:00.991015062 -0700
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 view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/783bfa72-5cef-4e48-88eb-ef07f7660b16%40googlegroups.com.