amisadmin / fastapi-amis-admin

FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.
http://docs.amis.work
Apache License 2.0
1.05k stars 154 forks source link

Extend search futures #137

Open MatsiukMykola opened 11 months ago

MatsiukMykola commented 11 months ago

hello, please add

ADDITIONAL_OPERATORS = {
    "similarity": lambda f, v: f.op("<->")(v),
    "word_similarity": lambda f, v: f.op("<->>")(v),
    "like": lambda f, v: f.ilike(v),
    "ilike": lambda f, v: f.ilike(v),
    "trigram_similar": lambda f, v: f.op("%%")(v),
    "trigram_startswith": lambda f, v: f.op("%%")(v + "%"),
    "trigram_endswith": lambda f, v: f.op("%%")("%" + v),
}

to fastapi_amis_admin\crud_sqlalchemy.py

sql_operator_pattern: Pattern = re.compile(r"^\[(=|<=|<|>|>=|!|!=|<>|\*|!\*|~|!~|-)]")
sql_operator_map: Dict[str, str] = {
    "=": "__eq__",
    "<=": "__le__",
    "<": "__lt__",
    ">": "__gt__",
    ">=": "__ge__",
    "!": "__ne__",
    "!=": "__ne__",
    "<>": "__ne__",
    "*": "in_",
    "!*": "not_in",
    "~": "like", # maybe just replace to ilike ???
    "!~": "not_like",
    "-": "between",
}

or need some way to extend in runtime flexibly

my ugly way to global ovveride: # extend amis-admin search futures, example: [~]%Yogurt%

sql_operator_map["~"] = "like"
MatsiukMykola commented 11 months ago

anyway i have work good solution to parse mongo-style queries to sqlalchemy, work fine in many projects:

sample:

  {
                    "limit": 5,
                    "skip": 1,
                    # can be string or List[str]
                    # 'order_by': 'price desc, name asc',
                    "order_by": ["price desc", "name asc"],
                    # can be string, search-term or dict
                    "where": {"or": [{"price": {"lt": 100}}, {"price": {"gt": 66}}]},
                    # calculate count (need only for pagination), don't use if you don't need them
                    "with_count": True,
                }

I can help implement this side or public this project main future: nested conditions

from you side - need you support something like: https://querybuilder.js.org/ in UI