On Wednesday, October 12, 2016 at 10:42:38 AM UTC-7, Alexander Birkner
wrote:
>
> Hello,
>
> we are migrating our existing backend from PHP to Ruby.
> We are using Sequel with Models but we can't do some queries because there
> is no way to use the MySQL function UNIX_TIMESTAMP.
>
> I would like to create a query like this:
>
> Service.where(
> :field_1 => 0,
> :field_2 => 0,
> :field_3 => Service::SERVICE_STATUS_ACTIVE,
> ).where{
> (suspend_date - Sequel::UNIX_TIMESTAMP) > 0
> }.where {
> (suspend_date - Sequel::UNIX_TIMESTAMP) < time
>
> }
>
>
> I've seen there is already existing a CURRENT_TIMESTAMP constant but this
> does not work in our case.
> The existing database field is a int instead of a datetime field.
>
> It would be really awesome if Sequel will add the UNIX_TIMESTAMP mysql
> method for Model queries.
>
> I've done it temporary with using a timestamp variable (timestamp =
> DateTime.now.to_i)
> but I would recommend to use the MySQL server time instead of the API
> server time.
>
> Thank you very much!
>
I don't plan on adding specific support for this in Sequel, it seems to be
a MySQL specific thing. It's just a regular function call anyway, you can
just use Sequel's function support:
Service.where(
:field_1 => 0,
:field_2 => 0,
:field_3 => Service::SERVICE_STATUS_ACTIVE).
where{suspend_date - UNIX_TIMESTAMP{} > 0}.
where{suspend_date - UNIX_TIMESTAMP{} < time}
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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.