coleifer/peewee — Issue #32: QueryResultWrapper.first()
Author: coderbuzz
Created: 2011-12-25 15:13:08+00:00
State: open

get() is not suitable in some cases, for example if we need get first row from complex select-where query, using join, sub-query etc (without exception)

Can you please add a first() method to QueryResultWrapper class?
The method should return None on empty resultset, otherwise return first row

Please check mind:

```python
class QueryResultWrapper(object):
# ...
def first(self):
if self._result_cache:
return self._result_cache[0]
else:
row = self.cursor.fetchone()
if row:
row_dict = self._row_to_dict(row, self.cursor)
instance = self.model_from_rowset(self.model, row_dict)
self._result_cache.append(instance)
return instance
else:
self._populated = True
return None
```