Hi Jeremy,

Thanks for the reply. Is there any way to define things like this in a 
common place? I meant to ask, Can we define a method that contains this 
case statement and call it inside the virtual row block?

Something like this:
Sequel.define_method_in_row_block(:day_of_week) do |column|
case DB.database_type
when :mysql
  # ...
when :postgres
  # ...
when :sqlite
  # ...
end

Then, we can simply call "Event.where{day_of_week(starts_at) =~ 1}" and 
make our code cleaner. That would be really helpful.

Thanks,
Satya


On Tuesday, February 7, 2017 at 1:28:30 PM UTC+5:30, Jeremy Evans wrote:
>
> On Monday, February 6, 2017 at 9:32:55 PM UTC-8, Satyanarayana Gandham 
> wrote:
>>
>> Hi,
>>
>> I have a Sequel Model (Event) which has a DateTime column(start_time), 
>> Now, I want to get all the events which starts on Sunday. Since, my 
>> development database is MySQL, I would do as 
>> "Event.where{DAYOFWEEK(starts_at) =~ 1}". Here, `DAYOFWEEK` is a MySQL 
>> specific function. But we want to use other databases like PostgreSQL or 
>> SQLite. The mysql functions doesn't work in other databases.
>>
>> What will I have to do to make it work on multiple databases(relational)?
>>
>
> In general, you can use a case statement for this:
>
> case DB.database_type
> when :mysql
>   # ...
> when :postgres
>   # ...
> when :sqlite
>   # ...
> end
>
> 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.

Reply via email to