I’m trying to do something similar to this, but really struggling to comprehend the query syntax. This is probably the wrong place, but it’s a good example, so a couple of questions:
Where does ?details come from? and ‘?summary’?
Are they some how generated from the page content itself? If so, how does this happen? What other things become available?
If they are built-in things, then where do I find a list of these? They’re not in the advanced queries doc
How do the where clauses combine? Is it something like:
each one applied sequentially to the results of the find clause, as a filter, or
as a function that may retrieve extra data and store it in a temporary variable (any vectory that ends in ?something where that something is not already defined?)
(that variable might be returned later with :keys)
Are your 3 groupings of vectors semantic, or just for easier reading?
Your first 3 where lines and your last three seem basically the same (two filters on block properties), but you’re using one before the :block/page filter in the middle group, and one after it. How does this work? Does this mean that it’s NOT sequential?
I have been doing other reading (e.g. the datomic docs, learndatalogtoday, and I found some of those resources in the wiki you linked, but hadn’t found the wiki itself). I’ve been reading clojure tutorials too (I’m primarily a python coder, only know lisp-family stuff out of general interest in coding languages). I have been trying to experiment a lot, but I’ve been struggling with the lack of clear feedback with errors. I see you posted about keeping the console open in another post, so I’ll try that.
Your extended reply is EXTREMELY helpful, and very clear, so thank you very much.
This is a game-changer for me. This makes it make a lot more sense.
A clarification: I think this means that advanced queries always start with blocks (this is implict, not obvious from the docs), and in order to get pages, you have to use the :block/page key(?), and then the (pull ?page [*]) is used as a secondary database query that retrieves all the other attributes of a page and puts them in the results? is that right?
OK, this [?summary :block/page ?page] line is a bit of a head-scratcher. let me get this right:
there is an implicit ?ALL_BLOCKS variable that contains the list of all blocks in the database
-(consider this pseudo-code thinking if I don’t have the technical details right)
?details contains ?ALL_BLOCKS filtered to only include blocks that have the material:: Aluminium proerty.
?page contains all the pages that the blocks in ?details are owned by (not sure the right terminology here)
because the [?summary :block/page ?page] doesn’t reference ?details or some other variable first, ?summary is implicitly a new filter against ?ALL_BLOCKS,
which then also gets run through a block property filter on the next few lines.
This is wild/impressive to me. It sounds somehow recursive and difficult to implement (I probably don’t need to know the details yet). Very cool.
This worked-example explanation format is extremely useful. I’m wondering if it might be valuable to add such an example to the docs directly. If I wrote one up, referencing this thread, would you be up for reviewing it?
Also, I think the advanced queries docs page could do with a paragraph or two of plain-english intro to add some of this context, perhaps I could have a go at writing that too, if my understanding of the above is correct.
Agreed. I had a go anyway, and it was really useful for consolidating my understanding. Maybe I will sit on it for a couple of weeks, and see if I find any mistakes, the I’ll post it.