superduper icon indicating copy to clipboard operation
superduper copied to clipboard

Separate `Query` object into `Query` and `Executor`

Open blythed opened this issue 5 months ago • 1 comments

Currently:

class MongoQuery(Query):
    patterns = ['.*find', ...]
    
    def __getattr__(self, item):
        # returns the find query
        ...

    def _execute_find(self):
        # executes the find query
        return ...

Proposal: separate into Query for building the query, and Executor for executing the query. This should make it easier for developers building their own databackends.

class Query:
    def __init__(self, executor: Executor):
        self.executor = executor

class Executor:
    def __init__(self, parent):
        self.parent = parent
        
    def __getattr__(self, item):
        return getattr(self.parent)
        
    @abtractmethod
    def select(self, ...):
        ...

    @abtractmethod
    def filter(self, ...):
        ...
    
    @abtractmethod
    def insert(self, ...):
        ...

class MongoExecutor(self):
    def select(self, **kwargs):
        return self.find(kwargs)

    ...

blythed avatar Sep 18 '24 11:09 blythed