Read implementation
require 'httparty'
module App
module Collections
class MyCollection < ForestAdminDatasourceToolkit::Collection
include ForestAdminDatasourceToolkit::Schema
# [... Declare structure and capabilities]
def list(caller, filter, projection)
# Fetch all records on all requests (this is _very_ inefficient)
response = HTTParty.get('https://my-api/my-collection')
result = response.parsed_response['items']
if filter.condition_tree
result = filter.condition_tree.apply(response, self, caller.timezone)
end
if filter.sort
result = filter.sort.apply(result)
end
if filter.page
result = filter.page.apply(result)
end
if filter.segment
raise 'This collection does not implement native segments'
end
if filter.search
raise 'This collection is not natively searchable'
end
projection.apply(result)
end
def aggregate(caller, filter, aggregation, limit = nil)
# Fetch all records which should be aggregated
records = list(caller, filter, aggregation.projection)
# Use "in-process emulation" to aggregate the results
aggregation.apply(records, caller.timezone, limit)
end
end
end
endTips
Count queries
Last updated