fastapi-amis-admin icon indicating copy to clipboard operation
fastapi-amis-admin copied to clipboard

Extend search futures

Open MatsiukMykola opened this issue 8 months ago • 1 comments

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 avatar Oct 13 '23 10:10 MatsiukMykola