Reputation: 6299
I am using Ruby on Rails application and want to fetch the datasets, tables in a paginated manner.
Using gem 'google-cloud-bigquery'
for my application.
Here is code for creating Bigquery client
Google::Cloud::Bigquery.configure do |config|
config.project_id = project_id
config.credentials = credentials
end
@bigquery = Google::Cloud::Bigquery.new
Fetching datasets
datasets = @bigquery.datasets
Above line fetches only first 50 records. But I want use the pagination for the dataset list. How can I achieve it using this gem in Ruby on Rails?
Example:
Total datasets = 170
Limit per page = 30
Total no of pages = 6
Upvotes: 0
Views: 382
Reputation: 1072
You need to invoke the #next
method on it. From the docs itself the code snippet will look something like this
datasets = @bigquery.datasets
if datasets.next? # Checks if there are more datasets
next_datasets = datasets.next # gets the next dataset list.
end
It all is controlled by the token
returned in the last response which is the location of the next page. Regarding the page size itself, there seems to be a max variable if you look inside the next method which I am not sure where it is being set from initially.
Upvotes: 1