Add fetch_where, a single conditional wrapper around fetch_if, similar to fetch_equals

This commit is contained in:
Ege Emir Özkan
2020-08-10 06:29:20 +03:00
parent a3eed28f42
commit f0aac81209
3 changed files with 19 additions and 2 deletions

View File

@@ -241,6 +241,19 @@ def fetch_if(class_: type, condition: str) -> tuple:
return tuple(_convert_record_to_object(class_, record, field_names) for record in records)
def fetch_where(class_: type, field: str, value: Any) -> tuple:
"""
Fetch all class_ type variables from the bound db,
provided that the field of the records fit the
given value.
:param class_: Class of the records.
:param field: Field to check.
:param value: Value to check for.
:return: A tuple of the records.
"""
return fetch_if(class_, f"{field} = {_convert_sql_format(value)}")
def fetch_range(class_: type, range_: range) -> tuple:
"""
Fetch the records in a given range of object ids.