Sha256: b98ec24d0159e7d6bbb810ee63fedd48e42fa877dd5256bf79cd3c13603a1a46
Contents?: true
Size: 1 KB
Versions: 6
Compression:
Stored size: 1 KB
Contents
module StateOfTheNation class QueryString def self.query_for(type, klass) database_appropriate_types(klass)[type] % { finish_key: klass.finish_key, start_key: klass.start_key } end def self.database_appropriate_types(klass) return { postgresql: { active_scope: "(%{finish_key} IS NULL OR %{finish_key} > ?::timestamp) AND %{start_key} <= ?::timestamp", less_than: "(%{start_key} < ?::timestamp)", greater_than_or_null: "(%{finish_key} > ?::timestamp) OR (%{finish_key} IS NULL)", }, mysql: { active_scope: "(%{finish_key} IS NULL OR %{finish_key} > ?) AND %{start_key} <= ?", less_than: "(%{start_key} < ?)", greater_than_or_null: "(%{finish_key} > ?) OR (%{finish_key} IS NULL)" } }[appropriate_db_type(klass)] end def self.appropriate_db_type(klass) case klass.connection.adapter_name when /PostgreSQL/ :postgresql else :mysql end end end end
Version data entries
6 entries across 6 versions & 1 rubygems