persvr / rql

Resource Query Language
http://www.persvr.org/
267 stars 49 forks source link

PHP RQL parser and data structure #43

Closed ghost closed 10 years ago

ghost commented 10 years ago

Hi! I intend to use your query language for a PHP REST API. I intend to use DDD with CQRS under the hud, so the GET requests will be converted into Query subclass instances (for example GetUserByIdQuery), and those instances will be processed by the query domain logic. These Query subclass instances should contain the resource id, possibly some additional data (for example user identity) and possibly the RQL conditions transformed to an easy traversable data structure. So by sending such a Query to a storage adapter, it can easily convert it to SQL, noSQL, or whatever queries it uses. Do you have some recommendations about the parser and the data structure?

neonstalwart commented 10 years ago

https://github.com/persvr/rql#rqlparser shows the data structure and https://github.com/persvr/rql/blob/master/parser.js contains the parser written in JS but it should translate fairly simply to PHP - it would just take some effort.

if you ask a more specific question we might be able to give you a more specific answer.

wshager commented 10 years ago

When recreating the parser I'd stick to the js version as much as possible. This means the parser will create a generic Query object that may be traversed, modified, stringified and, last but not least, used to page through and filter the dataset.

Applying rql can be done by converting the Query object for each adapter/storage layer, traversing each function type and arguments, and either applying the (no)SQL query while you traverse, or (more likely) creating a query (string) native to your adapter from the traversal and evaluating it at the end. You can have a look at js-array for a native js query or perstore/store/sql for a conversion from rql to sql.

Imo rql is meant to be a generic query language, and doesn't or shouldn't interfere with the model or C(R)UD. When implementing persvr in xquery, I created two libraries: rql and model. In case you're interested you can find them under my github profile.

ghost commented 10 years ago

Thanks for both of you! I'll read more, and will be back in a few days.

neonstalwart commented 10 years ago

closing this out as part of triaging bugs

narcoticfresh commented 10 years ago

Hi guys.. Just fyi, we're trying to start a PHP based RQL parser, located here: https://github.com/libgraviton/php-rql-parser

I've just started this yesterday and I'm off to my holidays a day after, but I hope my colleague will work on it while I'm away or maybe other ppl want to contribute..

Maybe check back in some weeks for any progress ;-)

amrlafi commented 7 years ago

Hi, I'm trying to develop .NET parser. Does this project, or php-rql-parser used a parser generator tool such as ANTLR or similar?

wshager commented 7 years ago

@amrlafi No, it doesn't. AFAIK it's overkill to use a formal grammar, since RQL is really just parentheses-only. You're welcome to write one of course, but you could also take a look at the regular expressions in the code or write a simple recursive descent parser.