Holochain Forum

How to do "hdk::query" with a condition(s)?

Say, I need to retrieve all Entities “Article” by a certain condition(s). All articles with the status = “A” and the title which contains “bb”, for instance.

hdk::query() doesn’t support that, does it? If not, how to do that properly? Retrieve all articles by hdk::query("article", 0, 0) – to the memory – and filter them by the means of Rust – via filter(...)? Is this the only way? What if there’re millions of them?

Hi @alx — I moved your post to #technical:app-development.

Right now hdk::query() has pretty limited filtering capabilities, as you say. In order to do the sort of querying you talk about, the underlying storage layer would have to understand something about the structure of the data. But presently the storage layer only understands data as strings.

I suspect that in the future we’ll need to take a look at making it easier to query data in a way that doesn’t require moving all entries into memory. My hunch is that this will look like having the storage layer understand whether the data being handed to it is JSON or a string, and indexing it accordingly. But there aren’t any plans yet.

So for now, you’re doing it exactly the way you should. In these early stages it makes the most sense for our core team to build functionality to a usable state, then focus on efficiency later.

1 Like