The easiest way that I was able to get something along the lines of what I wanted was to add new repositories.
Datamapper.setup(:default), <Insert database connection url>
DataMapper.setup(:onemonth), <Insert the same database url>
Datamapper.setup(:oneyear), <Insert the same database url>
In the model class,
class Klass
storage_name[:default] = "table"
storage_name[:onemonth] = "table_1_month"
storage_name[:oneyear] = "table_1_year"
# Psuedocode
def get_from_timeperiod(start_time, end_time)
time_one_year_ago = <some other int>
time_one_month_ago = <some int>
if end_time < time_one_month_ago
DataMapper.repository(:onemonth) { self.all( self.updated => (start_time..end_time) ) }
elif end_time < time_one_year_ago
DataMapper.repository(:oneyear) { self.all( self.updated => (start_time..end_time) ) }
else
self.all( self.updated => (start_time..end_time) )
end
end
end
(Update 10/31 6:13pm) The other alternative that I found is to use a direct database query instead of the DataMapper.repository(:onemonth) { } which results to struct objects:
repository(:default).adapter.select("SELECT * FROM table_one_month WHERE updated between #{start_time} and #{end_time}")
I personally find that the first way is a lot cleaner.
Please let me know if there's anything better that I can do!