aws / aws-sdk-ruby-record

Official repository for the aws-record gem, an abstraction for Amazon DynamoDB.
Apache License 2.0
318 stars 41 forks source link

Is query limit supported? #39

Closed imack closed 7 years ago

imack commented 7 years ago

I'm having some trouble limiting the results of a query on an index. I keep trying to impose a limit of 50 but I still get all the results that match the index query. Is Limit supported? or am I missing something?

Post.query(
        index_name: "blog_id-posted_time-index",
        key_condition_expression: "#H = :h AND #R < :r",
        limit: 50,
        expression_attribute_names: {
            "#H" => "blog_id",
            "#R" => "posted_time"
        },
        expression_attribute_values: {
            ":h" => blog_uuid,
            ":r" => timestamp
        }
    )

Where Post includes Aws::Record.

awood45 commented 7 years ago

The :limit parameter is respected, but the #query method is returning an enumerable object which will automatically paginate - in essence, it is respecting your limit per request, but making additional requests.

awood45 commented 7 years ago

The collection type is documented here.

One option is to also limit the number of items you take from the response - depends on your use case. The class doesn't currently expose the underlying response object.

imack commented 7 years ago

@awood45 gotcha; thanks for such a prompt reply; will construct statue in your honour when I rule the world.