Table.get now supports queries
This commit is contained in:
+19
-4
@@ -34,10 +34,25 @@ class RecordTable(table.Table):
|
||||
doc.after_insert(self._db)
|
||||
return doc.deserialize(self._db)
|
||||
|
||||
def get(self, doc_id: int, recurse: bool = False):
|
||||
document = super().get(doc_id=doc_id)
|
||||
if document:
|
||||
return document.deserialize(self._db, recurse=recurse)
|
||||
def get(self, *args, doc_id: int = None, recurse: bool = False, **kwargs):
|
||||
"""
|
||||
Return exactly zero or one records from the database matching the supplied criteria.
|
||||
If more than one records match the criteria, return the first one. Criteria are ignored
|
||||
if doc_id is specified.
|
||||
|
||||
Usage:
|
||||
Table.get(doc_id=1)
|
||||
Table.get(where("uid") == "abcdef")
|
||||
|
||||
"""
|
||||
if doc_id:
|
||||
document = super().get(doc_id=doc_id)
|
||||
if document:
|
||||
return document.deserialize(self._db, recurse=recurse)
|
||||
|
||||
matches = self.search(*args, recurse=recurse, **kwargs)
|
||||
if matches:
|
||||
return matches[0]
|
||||
|
||||
def search(self, *args, recurse: bool = False, **kwargs) -> List[Record]:
|
||||
results = super().search(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user