Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize the QueryModel #2523

Open
jieguangzhou opened this issue Oct 11, 2024 · 0 comments
Open

Optimize the QueryModel #2523

jieguangzhou opened this issue Oct 11, 2024 · 0 comments

Comments

@jieguangzhou
Copy link
Collaborator

jieguangzhou commented Oct 11, 2024

For the Model

we can set a flag attribute: is_query (or use another name).

If is_query is set to True, then on the front end, all models with is_query can be automatically returned, eliminating the need to add a default QueryTemplate.

Additionally, the parameter box can be rendered dynamically based on the predict parameters.

model = MyModel(identifier="mymodel", is_query=True)

For the Query Select
This is built-in

class QueryModel(Model):
    query_func: Callable
    is_query: bool = True

    def __post_init__(self):
        self.identifier = self.identifier or self.query_func.__name__

    def predict(self, **args, **kwargs):
        return self.query_func(self.db, **args, **kwargs)

This is the user’s usage.

def get_limit_datas(db, table_name: str, filter: dict, limit: int=50, filter):
    select = db[table_name].find(filter).limit(limit)
    return list(select.execute())

q = QueryModel(query_func=get_limit_datas)

db.apply(q)

We can generate such a JSON, and the frontend can generate the corresponding page based on this JSON.​

{
    "model": "get_limit_datas",
    "parameters": {
        "table_name": "",
        "filter": {},
        "limit": 50
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant