Skip to content

Commit 9400af8

Browse files
committed
Add all() function to the ResultSet API
1 parent d59af15 commit 9400af8

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
3.22.0
2+
======
3+
UNRELEASED
4+
5+
Features
6+
--------
7+
* Add all() function to the ResultSet API (PYTHON-1203)
8+
19
3.21.0
210
======
311
January 15, 2020
@@ -31,6 +39,7 @@ Others
3139
* Remove *read_repair_chance table options (PYTHON-1140)
3240
* Avoid warnings about unspecified load balancing policy when connecting to a cloud cluster (PYTHON-1177)
3341
* Add new DSE CQL keywords (PYTHON-1122)
42+
* Publish binary wheel distributions (PYTHON-1013)
3443
3544
Deprecations
3645
------------

cassandra/cluster.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4934,6 +4934,15 @@ def current_rows(self):
49344934
"""
49354935
return self._current_rows or []
49364936

4937+
def all(self):
4938+
"""
4939+
Returns all the remaining rows as a list. This is basically
4940+
a convenient shortcut to `list(result_set)`.
4941+
4942+
This function is not recommended for queries that return a large number of elements.
4943+
"""
4944+
return list(self)
4945+
49374946
def one(self):
49384947
"""
49394948
Return a single row of the results or None if empty. This is basically

tests/unit/test_resultset.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ def test_one(self):
195195

196196
self.assertEqual(rs.one(), first)
197197

198+
def test_all(self):
199+
first, second = Mock(), Mock()
200+
rs1 = ResultSet(Mock(has_more_pages=False), [first, second])
201+
rs2 = ResultSet(Mock(has_more_pages=False), [first, second])
202+
203+
self.assertEqual(rs1.all(), list(rs2))
204+
198205
@patch('cassandra.cluster.warn')
199206
def test_indexing_deprecation(self, mocked_warn):
200207
# normally we'd use catch_warnings to test this, but that doesn't work

0 commit comments

Comments
 (0)