json-logic-js
json-logic-js copied to clipboard
Translate to SQL?
Scenario:
- Have a website with a large form with check/text boxes and filter the data set
- PHP has to query MySQL with a boolean query like "... WHERE a > 3 AND ( b='x' OR b='y') "
Would be super handy to have a function that returns the SQL given a "logic" object!
Sorry for the slow response. This is totally doable, did you mean to open this issue on the PHP interpreter? https://github.com/jwadhams/json-logic-php/issues
Shoot.. I was hoping for this same thing. Rather than running the rule against data to get a result, I want to run the rule through a transform to turn it into a corresponding SQL expression
Hi I have exactly the same need (SQL translation of jsonlogic rule) for my project. Someone did it ?
I have a function that takes most of the logic operations and converts them to SQL conditions in PostgreSQL syntax. Unfortunately, I don't think it is very reusable at the moment though. I'll put it in the wiki in the hopes that someone might find it useful.
@pallione This certainly isn't a drop-in solution, but maybe it will help you. https://github.com/jwadhams/json-logic-js/wiki/Translate-logic-to-SQL-conditions