ticket_mule
ticket_mule copied to clipboard
Database agnostic query?
It would be nice to have these two queries work in all three db flavors (MySQL, SQLite and Postgresql). In the meantime, here are the queries that work for the associated databases:
Postgresql
Ticket.timeline_opened_tickets: self.count(:group => 'date(created_at)', :having => ['date(created_at) >= ? and date(created_at) <= ?', (Time.zone.now.beginning_of_day - 30.days).to_date.to_s, (Time.zone.now.end_of_day - 1.day).to_date.to_s])
Ticket.timeline_closed_tickets: self.count(:group => 'date(closed_at)', :having => ['date(closed_at) >= ? and date(closed_at) <= ?', (Time.zone.now.beginning_of_day - 30.days).to_date.to_s, (Time.zone.now.end_of_day - 1.day).to_date.to_s])
MySQL & SQLite
Ticket.timeline_opened_tickets: self.count(:group => 'date(created_at)', :having => ['date_created_at >= ? and date_created_at <= ?', (Time.zone.now.beginning_of_day - 30.days).to_date.to_s, (Time.zone.now.end_of_day - 1.day).to_date.to_s])
Ticket.timeline_closed_tickets: self.count(:group => 'date(closed_at)', :having => ['date_closed_at >= ? and date_closed_at <= ?', (Time.zone.now.beginning_of_day - 30.days).to_date.to_s, (Time.zone.now.end_of_day - 1.day).to_date.to_s])
Could you detect the type of Database Adapter being used and use alternate queries?