I’ve been trying to issue the following query via a state-script function: page where tags = "journal" order by created desc via the datastore.query syscall.
I had a look at the Query type taken by datastore.query and after a couple of iterations, I came up with
```space-script
silverbullet.registerFunction("queryJournalEntries", async (query) => {
return await syscall("datastore.query", query);
// I'd like to perform further filtering and aggregation after that
})
You got quite far! While you can probably get this to work , I’d recommend using a call at a slightly higher level of abstraction. This is an API not exposed as a syscall, but as a function on the index plug.
Specifically, queryObjects defined here:
I have no access to a laptop to test and I’m typing this on my phone, but it would look something like: syscall("system.invokeFunction", "index.queryObjects", "journal", {orderBy: [{expr: ["string", "created"], desc: true})
You can narrow it down more in that query object, but querying the “journal” tag directly should get you there without an additional filter.
As a conclusion, here’s how the final implementation works.
I have a list of journal entries with associated mood. I defined a generic groupBy function, as well as the function to query pages by a given tag you helped me with.