Skip to content

Conversation

@gonewest818
Copy link

Prior to this PR it was possible to do a simple {:find ... :where } but more sophisticated queries were not yet possible.

Now we have full support for the query keywords :find, :where, :in, :rules, :order-by, :limit, :offset, and :timeout. For the :in clause we also provide an .in_args() to bind arguments to those parameters. In other words you can now form a query like this:

    result = node.find('?e') \
                 .where('?e :name first') \
                 .where('?e :last-name last') \
                 .in_('first last') \
                 .in_args('Billy', 'Joel')

which is equivalent to

    {:find [?e] :where [[?e :name first] [?e :last-name last]] :in [first last]}

with first bound to "Billy" and last bound to "Joel".

Because the underlying pyxtdb.Node.query() method supports EDN parsed from strings, so do these methods, in other words if you wanted to you could form the same query like this:

    result = node.find(Symbol('?e')) \
                 .where(Symbol('?e'), Keyword('name'), Symbol('first')) \
                 .where(Symbol('?e'), Keyword('last-name'), Symbol('last')) \
                 .in_(Symbol('first'), Symbol('last')) \
                 .in_args('Billy', 'Joel')

This latter form might be a bit more amenable to people wanting to construct queries dynamically. It remains to be seen how that plays out in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants