Customer wants to be able to write highly customized universal conditions for scheduled reports for his intranet website. Think about something similar to JIRA and Jira Query Language (JQL).

Is there any good, well documented library to provide a solid base for custom query language development? Some parser, lexer etc. and an option to easily visit the nodes and map to actual DB queries?

I did some internet search, but maybe I'm not good at using the right keywords because I could not find anything useful.

I'm aware that there are no completely universal tools because we will have to implement mappings from query to our SQL schema (to deal with situations when customer enters "user.role = 'Administrator'" and we have to map it to user.role_id = (SELECT from roles where name = 'Administrator' LIMIT 1)) and we might never reach full coverage, but we'll add support for more fields and search queries as we go. It would be great just to avoid writing custom parsers, lexers etc.

  • To give you a keyword: What you're looking for is most likely Object-relational mapping (ORM), which maps "objects" (think of your "user" object here) to database models (the "users" table, or whatever you use, and its "dependencies"). It that's it: while waiting for answers, you could browse this list of PHP ORM frameworks. – Izzy Oct 25 '17 at 12:26
  • Actually, I'm already using ORM - Laravel Eloquent and QueryBuilder. But that solves completely different problem - it maps code objects to database entities purely on the server side, while I need something to expose to the end user, so he can type a query, like "ticket.status = opened and ticket.deadline = tomorrow" and it gets tokenized in my code and then I can translate it to the Laravel QueryBuilder. Or think from this viewpoint - I need "safe SQL injection" where user is allowed to write something similar to SQL query conditions. – JustAMartin Oct 25 '17 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.