Skip to content

Commit d4c06c5

Browse files
authored
feat: add MySQL chart compatibility (#30)
* feat: add Mysql chart compatibility * fix: Rubocop issues
1 parent ea3f846 commit d4c06c5

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

app/services/solid_queue_monitor/chart_data_service.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,19 @@ def fill_buckets(buckets, index_counts)
8181
# Cross-DB bucket index expression.
8282
# PostgreSQL: CAST((EXTRACT(EPOCH FROM col) - start) / interval AS INTEGER)
8383
# SQLite: CAST((CAST(strftime('%s', col) AS INTEGER) - start) / interval AS INTEGER)
84+
# MySQL: CAST((UNIX_TIMESTAMP(col) - start) / interval AS SIGNED)
8485
def bucket_index_expr(column, start_epoch, interval_seconds)
85-
if sqlite?
86+
if adapter?('sqlite')
8687
"CAST((CAST(strftime('%s', #{column}) AS INTEGER) - #{start_epoch}) / #{interval_seconds} AS INTEGER)"
88+
elsif adapter?('mysql')
89+
"CAST((UNIX_TIMESTAMP(#{column}) - #{start_epoch}) / #{interval_seconds} AS SIGNED)"
8790
else
8891
"CAST((EXTRACT(EPOCH FROM #{column}) - #{start_epoch}) / #{interval_seconds} AS INTEGER)"
8992
end
9093
end
9194

92-
def sqlite?
93-
ActiveRecord::Base.connection.adapter_name.downcase.include?('sqlite')
95+
def adapter?(name)
96+
ActiveRecord::Base.connection.adapter_name.downcase.include?(name)
9497
end
9598
end
9699
end

0 commit comments

Comments
 (0)