Return a single row of the results or None if empty. This is basically a shortcut to `result_set.current_rows[0]` and should only be used when you know a query returns a single row. Consider using an iterator if the ResultSet contains more than one row.
(self)
| 5227 | return list(self) |
| 5228 | |
| 5229 | def one(self): |
| 5230 | """ |
| 5231 | Return a single row of the results or None if empty. This is basically |
| 5232 | a shortcut to `result_set.current_rows[0]` and should only be used when |
| 5233 | you know a query returns a single row. Consider using an iterator if the |
| 5234 | ResultSet contains more than one row. |
| 5235 | """ |
| 5236 | row = None |
| 5237 | if self._current_rows: |
| 5238 | try: |
| 5239 | row = self._current_rows[0] |
| 5240 | except TypeError: # generator object is not subscriptable, PYTHON-1026 |
| 5241 | row = next(iter(self._current_rows)) |
| 5242 | |
| 5243 | return row |
| 5244 | |
| 5245 | def __iter__(self): |
| 5246 | if self._list_mode: |
no outgoing calls