superduper
superduper copied to clipboard
Optimize the QueryModel
trafficstars
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
}
}