Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def exec(self, transaction_or_batch=None):
"""return modified instance of model"""
if transaction_or_batch:
return self._raw_exec(transaction_or_batch)
return query_wrapper.ModelWrapper.from_query_result(self.model, self._raw_exec())
def __next__(self):
try:
doc = next(self.docs, None)
if doc:
# Suppose this is the last doc
self.last_doc = doc
m = query_wrapper.ModelWrapper.from_query_result(self.model_cls(), doc)
m._update_doc = self.query._update_doc_key(m)
# Suppose this is last doc
self.last_doc_key = m.key
return m
self.fetch_end = True
# Save last doc key in cursor
self.query.cursor_dict['last_doc_key'] = self.last_doc_key
raise StopIteration
except Exception:
raise StopIteration
def exec(self):
"""return modified or new instance of model"""
return query_wrapper.ModelWrapper.from_query_result(self.model, self._raw_exec())
def exec(self, transaction=None):
"""Wrap the query result into model instance"""
return query_wrapper.ModelWrapper.from_query_result(self.model, self._raw_exec(transaction))
def get(self):
"""Get the first matching document from firestore
Get first matching document and convert it into model and return it
This is same as `fetch(limit=1)` the only difference is `get()` method
return **model instance** and the `fetch()` method return the **generator**
"""
self.n_limit = 1
doc = next(self.query().stream(self.query_transaction), None)
if doc:
m = query_wrapper.ModelWrapper.from_query_result(self.model, doc)
m._update_doc = self._update_doc_key(m)
return m
return None
def exec(self, transaction_or_batch=None):
"""return modified or new instance of model"""
if transaction_or_batch:
return self._raw_exec(transaction_or_batch)
return query_wrapper.ModelWrapper.from_query_result(self.model, self._raw_exec())