Is your feature request related to a problem? Please describe.
Now, CRUDRepository supports only standard auto-generated methods (find_by_id, save, etc.).
It's difficult to use it widely without a way to define custom methods like find_one_by_passport_number.
Describe the solution you'd like
This is an example of a custom method I'd like to use in my repository:
class PersonRepository(CRUDRepository[Person, UUID]):
def find_one_by_passport_number(self, passport_number: str) -> Optional[Person]:
result = self._get_query().filter(Person.passport_number == passport_number).values(Person.id)
id_ = next(result, None)
if id_ is None:
return None
return self.find_by_id(id_)
Describe alternatives you've considered
Would be also cool to auto-generate this kind of method just by its name.
class PersonRepository(CRUDRepository[Person, UUID]):
def find_one_by_passport_number(self, passport_number: str) -> Optional[Person]:
pass
It allows avoiding to do two SQL queries instead of one. Or avoiding to do one SQL query but complex logic with session factory etc.
Is your feature request related to a problem? Please describe. Now, CRUDRepository supports only standard auto-generated methods (find_by_id, save, etc.). It's difficult to use it widely without a way to define custom methods like
find_one_by_passport_number
.Describe the solution you'd like This is an example of a custom method I'd like to use in my repository:
Describe alternatives you've considered Would be also cool to auto-generate this kind of method just by its name.
It allows avoiding to do two SQL queries instead of one. Or avoiding to do one SQL query but complex logic with session factory etc.
Additional context No.