piccolo-orm / piccolo

A fast, user friendly ORM and query builder which supports asyncio.
https://piccolo-orm.com/
MIT License
1.46k stars 91 forks source link

Encode strings as JSON in `where` clauses #1118

Open dantownsend opened 1 month ago

dantownsend commented 1 month ago

We just added more powerful JSON filtering, but when integrating it into Piccolo Admin, I realised there's a bug here:

https://github.com/piccolo-orm/piccolo/blob/448a818e3e7420e6f052b6e79473bbeee0b3e76f/piccolo/query/operators/json.py#L15-L16

We should also encode strings as JSON e.g. 'hello world' -> '"hello world"'. However, if the string is already valid JSON, we should leave it alone (e.g. '{"message": "hello world"}').