{"action":"created","comment":{"url":"https://api.github.com/repos/cloudant/python-cloudant/pulls/comments/46884122","id":46884122,"diff_hunk":"@@ -267,3 +269,138 @@ def __iter__(self):\n                 del result\n             else:\n                 break\n+\n+class QueryResult(object):\n+    \"\"\"\n+    Provides a sliceable and iterable interface to query result collections.\n+    A QueryResult object is instantiated with the Query\n+    :func:`~cloudant.query.Query.__call__` callable, which is used to retrieve\n+    data.  A QueryResult object can also use optional extra arguments for result\n+    customization and supports efficient, paged iteration over the result\n+    collection to avoid large result data from adversely affecting memory.\n+\n+    In Python, slicing returns by value, whereas iteration will yield\n+    elements of the sequence.  This means that slicing will perform better\n+    for smaller data collections, whereas iteration will be more\n+    efficient for larger data collections.\n+\n+    For example:\n+\n+    .. code-block:: python\n+\n+        # Slicing by value:\n+        query_result[100:200] # results between the 100th and the 200th result\n+        query_result[:200]    # results up to the 200th result\n+        query_result[100:]    # results after 100th result\n+        query_result[:]       # all results\n+\n+        # Iteration:\n+\n+        # Iterate over the entire result collection\n+        query_result = QueryResult(query)\n+        for doc in query_result:\n+            print doc\n+\n+        # Iterate over the result collection, with an overriding query sort\n+        query_result = QueryResult(query, sort=[{'name': 'desc'}])\n+        for doc in query_result:\n+            print doc\n+\n+        # Iterate over the entire result collection,\n+        # explicitly setting the index and in batches of a 1000.\n+        query_result = QueryResult(query, use_index='my_index', page_size=1000)\n+        for doc in query_result:\n+            print doc\n+    \"\"\"\n+    def __init__(self, query, **options):\n+        self.options = options\n+        self._query = query\n+        self._page_size = options.pop('page_size', 100)\n+\n+    def __getitem__(self, key):\n+        \"\"\"\n+        Provides query result slicing by element support.  Key access and\n+        slicing by non-integer key value are not available for query results.\n+\n+        See :class:`~cloudant.result.QueryResult` for slicing examples.\n+\n+        :param key:  Must be a range defined by two integers.  Slices\n+            will be interpreted as ``skip:limit-skip`` style pairs.\n+            For example ``[100:200]`` means skip 100 records\n+            then get up to and including the 200th record so that you get the\n+            range between the supplied slice values.  Whereas ``[:100]`` means\n+            get up to and including the 100th record.\n+\n+        :returns: Rows data in JSON format\n+        \"\"\"\n+        if 'skip' in self.options or 'skip' in self._query.keys():\n+            msg = 'Cannot use skip parameter with QueryResult slicing.'\n+            raise CloudantArgumentError(msg)\n+        if 'limit' in self.options or 'limit' in self._query.keys():\n+            msg = 'Cannot use limit parameter with QueryResult slicing.'\n+            raise CloudantArgumentError(msg)\n+        if (","path":"src/cloudant/result.py","position":165,"original_position":165,"commit_id":"552eabd78f6d7c16c934d00e22abebb6d2811966","original_commit_id":"552eabd78f6d7c16c934d00e22abebb6d2811966","user":{"login":"evansde77","id":342380,"avatar_url":"https://avatars.githubusercontent.com/u/342380?v=3","gravatar_id":"","url":"https://api.github.com/users/evansde77","html_url":"https://github.com/evansde77","followers_url":"https://api.github.com/users/evansde77/followers","following_url":"https://api.github.com/users/evansde77/following{/other_user}","gists_url":"https://api.github.com/users/evansde77/gists{/gist_id}","starred_url":"https://api.github.com/users/evansde77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evansde77/subscriptions","organizations_url":"https://api.github.com/users/evansde77/orgs","repos_url":"https://api.github.com/users/evansde77/repos","events_url":"https://api.github.com/users/evansde77/events{/privacy}","received_events_url":"https://api.github.com/users/evansde77/received_events","type":"User","site_admin":false},"body":"There seems to be a lot of common code between the Result and QueryResult classes, I would maybe look at subclassing the Result class in QueryResult to remove some of the dupe code. ","created_at":"2015-12-07T21:58:45Z","updated_at":"2015-12-07T21:58:45Z","html_url":"https://github.com/cloudant/python-cloudant/pull/37#discussion_r46884122","pull_request_url":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37","_links":{"self":{"href":"https://api.github.com/repos/cloudant/python-cloudant/pulls/comments/46884122"},"html":{"href":"https://github.com/cloudant/python-cloudant/pull/37#discussion_r46884122"},"pull_request":{"href":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37"}}},"pull_request":{"url":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37","id":52906064,"html_url":"https://github.com/cloudant/python-cloudant/pull/37","diff_url":"https://github.com/cloudant/python-cloudant/pull/37.diff","patch_url":"https://github.com/cloudant/python-cloudant/pull/37.patch","issue_url":"https://api.github.com/repos/cloudant/python-cloudant/issues/37","number":37,"state":"open","locked":false,"title":"Add query execution support - part one","user":{"login":"alfinkel","id":8793303,"avatar_url":"https://avatars.githubusercontent.com/u/8793303?v=3","gravatar_id":"","url":"https://api.github.com/users/alfinkel","html_url":"https://github.com/alfinkel","followers_url":"https://api.github.com/users/alfinkel/followers","following_url":"https://api.github.com/users/alfinkel/following{/other_user}","gists_url":"https://api.github.com/users/alfinkel/gists{/gist_id}","starred_url":"https://api.github.com/users/alfinkel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alfinkel/subscriptions","organizations_url":"https://api.github.com/users/alfinkel/orgs","repos_url":"https://api.github.com/users/alfinkel/repos","events_url":"https://api.github.com/users/alfinkel/events{/privacy}","received_events_url":"https://api.github.com/users/alfinkel/received_events","type":"User","site_admin":false},"body":"_What:_\r\n\r\n- Added query management functionality to the library.\r\n- Unit tests are complete but will be included in a follow up PR to keep the review process relatively manageable.  All unit tests have run successfully to completion.\r\n- Index management is **NOT** included in this PR either, it will also be included in a future PR.\r\n\r\n_Why:_\r\n\r\nThe library needs to provide query management functionality so that users do not have to access query functionality directly via the `_find` endpoint.\r\n\r\n_How:_\r\n\r\n- Added a Query class and query.py module to handle query parameter processing and request execution to the `_find` endpoint. Found in 4ff83bc.\r\n- Added a QueryResult class to the result.py module to handle slicing and iteration of query results.  Found in 4ff83bc.\r\n- Added a convenience method to the database.py module to execute queries.  Found in db6e822.\r\n- Updated documentation accordingly.  Found in 587841f, 40a23ac, 552eabd.\r\n\r\nreviewer: @evansde77 \r\n\r\nBugId:  51282","created_at":"2015-12-07T21:50:02Z","updated_at":"2015-12-07T21:58:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8adeeb7c4fc39ac1db5594f35a56513f3ad9389c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37/commits","review_comments_url":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37/comments","review_comment_url":"https://api.github.com/repos/cloudant/python-cloudant/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudant/python-cloudant/issues/37/comments","statuses_url":"https://api.github.com/repos/cloudant/python-cloudant/statuses/552eabd78f6d7c16c934d00e22abebb6d2811966","head":{"label":"cloudant:51282-add-query-support","ref":"51282-add-query-support","sha":"552eabd78f6d7c16c934d00e22abebb6d2811966","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":41557383,"name":"python-cloudant","full_name":"cloudant/python-cloudant","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/python-cloudant","description":"A Python library for Cloudant and CouchDB","fork":false,"url":"https://api.github.com/repos/cloudant/python-cloudant","forks_url":"https://api.github.com/repos/cloudant/python-cloudant/forks","keys_url":"https://api.github.com/repos/cloudant/python-cloudant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/python-cloudant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/python-cloudant/teams","hooks_url":"https://api.github.com/repos/cloudant/python-cloudant/hooks","issue_events_url":"https://api.github.com/repos/cloudant/python-cloudant/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/python-cloudant/events","assignees_url":"https://api.github.com/repos/cloudant/python-cloudant/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/python-cloudant/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/python-cloudant/tags","blobs_url":"https://api.github.com/repos/cloudant/python-cloudant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/python-cloudant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/python-cloudant/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/python-cloudant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/python-cloudant/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/python-cloudant/languages","stargazers_url":"https://api.github.com/repos/cloudant/python-cloudant/stargazers","contributors_url":"https://api.github.com/repos/cloudant/python-cloudant/contributors","subscribers_url":"https://api.github.com/repos/cloudant/python-cloudant/subscribers","subscription_url":"https://api.github.com/repos/cloudant/python-cloudant/subscription","commits_url":"https://api.github.com/repos/cloudant/python-cloudant/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/python-cloudant/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/python-cloudant/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/python-cloudant/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/python-cloudant/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/python-cloudant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/python-cloudant/merges","archive_url":"https://api.github.com/repos/cloudant/python-cloudant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/python-cloudant/downloads","issues_url":"https://api.github.com/repos/cloudant/python-cloudant/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/python-cloudant/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/python-cloudant/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/python-cloudant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/python-cloudant/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/python-cloudant/releases{/id}","created_at":"2015-08-28T16:22:49Z","updated_at":"2015-12-02T20:25:11Z","pushed_at":"2015-12-07T21:50:02Z","git_url":"git://github.com/cloudant/python-cloudant.git","ssh_url":"git@github.com:cloudant/python-cloudant.git","clone_url":"https://github.com/cloudant/python-cloudant.git","svn_url":"https://github.com/cloudant/python-cloudant","homepage":null,"size":335,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":5,"forks":2,"open_issues":5,"watchers":8,"default_branch":"master"}},"base":{"label":"cloudant:master","ref":"master","sha":"f7f5c7877687e6dd3a8e5ccc246cbb1df6974c54","user":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"repo":{"id":41557383,"name":"python-cloudant","full_name":"cloudant/python-cloudant","owner":{"login":"cloudant","id":44642,"avatar_url":"https://avatars.githubusercontent.com/u/44642?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudant","html_url":"https://github.com/cloudant","followers_url":"https://api.github.com/users/cloudant/followers","following_url":"https://api.github.com/users/cloudant/following{/other_user}","gists_url":"https://api.github.com/users/cloudant/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudant/subscriptions","organizations_url":"https://api.github.com/users/cloudant/orgs","repos_url":"https://api.github.com/users/cloudant/repos","events_url":"https://api.github.com/users/cloudant/events{/privacy}","received_events_url":"https://api.github.com/users/cloudant/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudant/python-cloudant","description":"A Python library for Cloudant and CouchDB","fork":false,"url":"https://api.github.com/repos/cloudant/python-cloudant","forks_url":"https://api.github.com/repos/cloudant/python-cloudant/forks","keys_url":"https://api.github.com/repos/cloudant/python-cloudant/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudant/python-cloudant/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudant/python-cloudant/teams","hooks_url":"https://api.github.com/repos/cloudant/python-cloudant/hooks","issue_events_url":"https://api.github.com/repos/cloudant/python-cloudant/issues/events{/number}","events_url":"https://api.github.com/repos/cloudant/python-cloudant/events","assignees_url":"https://api.github.com/repos/cloudant/python-cloudant/assignees{/user}","branches_url":"https://api.github.com/repos/cloudant/python-cloudant/branches{/branch}","tags_url":"https://api.github.com/repos/cloudant/python-cloudant/tags","blobs_url":"https://api.github.com/repos/cloudant/python-cloudant/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudant/python-cloudant/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudant/python-cloudant/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudant/python-cloudant/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudant/python-cloudant/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudant/python-cloudant/languages","stargazers_url":"https://api.github.com/repos/cloudant/python-cloudant/stargazers","contributors_url":"https://api.github.com/repos/cloudant/python-cloudant/contributors","subscribers_url":"https://api.github.com/repos/cloudant/python-cloudant/subscribers","subscription_url":"https://api.github.com/repos/cloudant/python-cloudant/subscription","commits_url":"https://api.github.com/repos/cloudant/python-cloudant/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudant/python-cloudant/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudant/python-cloudant/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudant/python-cloudant/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudant/python-cloudant/contents/{+path}","compare_url":"https://api.github.com/repos/cloudant/python-cloudant/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudant/python-cloudant/merges","archive_url":"https://api.github.com/repos/cloudant/python-cloudant/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudant/python-cloudant/downloads","issues_url":"https://api.github.com/repos/cloudant/python-cloudant/issues{/number}","pulls_url":"https://api.github.com/repos/cloudant/python-cloudant/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudant/python-cloudant/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudant/python-cloudant/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudant/python-cloudant/labels{/name}","releases_url":"https://api.github.com/repos/cloudant/python-cloudant/releases{/id}","created_at":"2015-08-28T16:22:49Z","updated_at":"2015-12-02T20:25:11Z","pushed_at":"2015-12-07T21:50:02Z","git_url":"git://github.com/cloudant/python-cloudant.git","ssh_url":"git@github.com:cloudant/python-cloudant.git","clone_url":"https://github.com/cloudant/python-cloudant.git","svn_url":"https://github.com/cloudant/python-cloudant","homepage":null,"size":335,"stargazers_count":8,"watchers_count":8,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":5,"forks":2,"open_issues":5,"watchers":8,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37"},"html":{"href":"https://github.com/cloudant/python-cloudant/pull/37"},"issue":{"href":"https://api.github.com/repos/cloudant/python-cloudant/issues/37"},"comments":{"href":"https://api.github.com/repos/cloudant/python-cloudant/issues/37/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudant/python-cloudant/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudant/python-cloudant/pulls/37/commits"},"statuses":{"href":"https://api.github.com/repos/cloudant/python-cloudant/statuses/552eabd78f6d7c16c934d00e22abebb6d2811966"}}}}