Valbou / vtaskr-backend

An open-source to do list application for personnal use
GNU General Public License v3.0
5 stars 0 forks source link

Create a SqlAlchemy Query Builder #21

Closed Valbou closed 1 year ago

Valbou commented 1 year ago

Create a query builder like Django QuerySet. It give reusable query and inheritance capabilities.

base = TagQueryset()
base.select().owner(user_id).done(True)
class Queryset:
    def __init__(self, qs_class):
        self.query = select(qs_class)

    def owner(self, user_id) -> Self:
        self.query = self.query.where(qs_class.user_id == user_id)
        return self

class TagQueryset:
    def __init__(self):
        self.query = select(Tag)