json-logic-js icon indicating copy to clipboard operation
json-logic-js copied to clipboard

Translate to SQL?

Open sscarduzio opened this issue 7 years ago • 4 comments

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!

sscarduzio avatar Jan 07 '17 18:01 sscarduzio

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

jwadhams avatar Jan 19 '17 16:01 jwadhams

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

deinspanjer avatar Mar 02 '17 23:03 deinspanjer

Hi I have exactly the same need (SQL translation of jsonlogic rule) for my project. Someone did it ?

pallione avatar Sep 05 '17 09:09 pallione

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

deinspanjer avatar Sep 07 '17 10:09 deinspanjer