Data: QueryChain
lhaze opened this issue · 2 comments
lhaze commented
It turned out that we need a query manipulation object, just like SQLAlchemy's Query
& Django ORM's QuerySet
. Predicate
class is good at expressing an universal condition but there is more to do:
- Not all operaterations' signatures of DAO make sense to have all cases of filtering (eg. exists). Using query chaining like
.filter(foo='bar').exists()
make more sense. - Sometimes you want to have final query built from a few predefined pieces (like having predefined user visibility queries and chaining them with a custom filter later).
lhaze commented
class SomeDao(IDao):
def aggregate(*vars: str) -> QueryChain: ...
def sort(*vars: str) -> QueryChain: ...
def filter(self, predicate: Predicate) -> QueryChain: ...
return QueryChain(self).filter(predicate)
def _resolve_filter(self, predicate):
return self.table
def exists(self) -> bool: ...
class QueryChain:
def __init__(self, dao):
def aggregate(*vars: str) -> QuerySet: ...
def sort(*vars: str) -> QuerySet: ...
def filter(predicate: Predicate) -> QuerySet: ...
def exists() -> bool: ...
lhaze commented
Done.