Class: Hyrax::CustomQueries::FindByDateRange
- Inherits:
-
Object
- Object
- Hyrax::CustomQueries::FindByDateRange
- Defined in:
- app/services/hyrax/custom_queries/find_by_date_range.rb
Overview
Instance Attribute Summary collapse
-
#query_service ⇒ Object
readonly
Returns the value of attribute query_service.
Class Method Summary collapse
Instance Method Summary collapse
- #find_by_date_range(start_datetime:, end_datetime: nil, models: nil) ⇒ Object
- #find_by_date_range_query ⇒ Object
- #find_models_by_date_range_query ⇒ Object
-
#initialize(query_service:) ⇒ FindByDateRange
constructor
A new instance of FindByDateRange.
Constructor Details
#initialize(query_service:) ⇒ FindByDateRange
Returns a new instance of FindByDateRange.
11 12 13 |
# File 'app/services/hyrax/custom_queries/find_by_date_range.rb', line 11 def initialize(query_service:) @query_service = query_service end |
Instance Attribute Details
#query_service ⇒ Object (readonly)
Returns the value of attribute query_service.
15 16 17 |
# File 'app/services/hyrax/custom_queries/find_by_date_range.rb', line 15 def query_service @query_service end |
Class Method Details
.queries ⇒ Object
7 8 9 |
# File 'app/services/hyrax/custom_queries/find_by_date_range.rb', line 7 def self.queries [:find_by_date_range] end |
Instance Method Details
#find_by_date_range(start_datetime:, end_datetime: nil, models: nil) ⇒ Object
Note:
this is an unoptimized default implementation of this custom query. it’s Hyrax’s policy to provide such implementations of custom queries in use for cross-compatibility of Valkyrie query services. it’s advisable to provide an optimized query for the specific adapter.
28 29 30 31 32 33 34 35 |
# File 'app/services/hyrax/custom_queries/find_by_date_range.rb', line 28 def find_by_date_range(start_datetime:, end_datetime: nil, models: nil) end_datetime = 1.second.since(Time.zone.now) if end_datetime.blank? if models.present? query_service.run_query(find_models_by_date_range_query, start_datetime.to_s, end_datetime.to_s, models) else query_service.run_query(find_by_date_range_query, start_datetime.to_s, end_datetime.to_s) end end |
#find_by_date_range_query ⇒ Object
46 47 48 49 50 51 52 |
# File 'app/services/hyrax/custom_queries/find_by_date_range.rb', line 46 def find_by_date_range_query <<-SQL SELECT * FROM orm_resources WHERE created_at >= ? AND created_at <= ?; SQL end |
#find_models_by_date_range_query ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'app/services/hyrax/custom_queries/find_by_date_range.rb', line 37 def find_models_by_date_range_query <<-SQL SELECT * FROM orm_resources WHERE created_at >= ? AND created_at <= ? AND internal_resource IN (?); SQL end |