Search code examples
phprethinkdbreql

Rethinkdb - PHP-RQL - Http api - filter response


I'm working through several tutorials and examples on Rethinkdb and converting them to PHP-RQL for my own learning.

I'm currently looking at http://www.infoworld.com/article/2975838/database/build-real-time-web-apps-with-rethinkdb.html and can't work out how to replicate this:

r.http("http://www.reddit.com/r/aww.json")("data")("children")("data").orderBy(r.desc("score")).limit(5).pluck("score", "title", "url")

Specifically, it's the initial filter ("("data")("children")("data")") which I'm struggling to recreate in PHP-RQL.

Any assistance would be appreciated please.

Thanks


Solution

  • Those query terms are the BRACKET terms from ReQL, and in this case (because they are being called with a string), they are equivalent to the GET_FIELD term. I haven't used the PHP client driver, but some docs for those terms are available here.

    These have examples on usage, which appear to be equivalent:

    Example: What was Iron Man's first appearance in a comic?

    $ironMan = r\table('marvel')->get('IronMan');
    $ironMan('firstAppearance')->run($conn)
    
    r\table('marvel')->get('IronMan')->getField('firstAppearance')->run($conn)
    

    Perhaps the BRACKET term can't be chained onto the query like most other terms.