Wednesday, May 17, 2017

Generate MySQL JSON_EXTRACT condition with user search parameter

Leave a Comment

I have a very special case where users can store their own JSON object for records. The reason is that every user has special objects and data structure which is part of his normal record.

I want to let users search for objects in the MySQL DB through my API. I am using the JSON_EXTRACT(json_field, "$ ...") ... syntax or in short the -> syntax.

Users should be able to make queries like this: get /service/resource?a>3 AND b.c="dog" OR b.d IS NOT NULL where all parameters (a, b) search on the json field.

First I thought of using a list of parameters, but how should I be able to get the AND, OR, IS NOT NULL operator combining them?

How would you design such a search function for a RESTful API?

1 Answers

Answers 1

Google is using "+" for building their queries. Google query "a AND B or NOT c" -> google.com/q=a+AND+b+or+NOT+c

I will try this approuch.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment