mvy
June 6, 2024, 10:49am
1
Hi,
I have lurked in the topics to help me come up with a query to put on my type
page. I use type
as a property to organise my stuff.
My goal was to get a list of pages that are missing the property type, and list them with link.
#+BEGIN_QUERY
{ :title [:b "Pages missing type" ]
:query [:find ?pagename
:where
[?b :block/properties ?prop]
[?b :block/name _]
[?b :block/original-name ?pagename]
(not [?b :block/journal? true])
(not [(get ?prop :type)])
]
:view (fn [result] (for [r result] [:div [:a.tag.mr-1 {:href (str "#/page/" (clojure.string/replace r "/" "%2F") )} r ] ] ) )
}
#+END_QUERY
This works great (it does list my whiteboards though, which bonus point if you can let me know how to filter them too)
Now what I’d like to do, is to be able to use that query on other property pages. So I have tried to use in/inputs like this:
:query [:find ?pagename
:in $ ?t
:where
[?b :block/properties ?prop]
[?b :block/name _]
[?b :block/original-name ?pagename]
(not [?b :block/journal? true])
(not [(get ?prop ?t)])
]
:inputs [:query-page]
but that does not seem to work. Can anyone help me pinpoint where I got things wrong?
1 Like
mvy
June 6, 2024, 11:15am
3
Ahh I figured as much. But, despite being a seasoned programmer, this clojure syntax is just so foreign to me!
Thank you very much!
Could try this for the whiteboard filter:
(not
[(get ?prop :ls-type) ?lstype]
[(keyword "whiteboard-page") ?wb]
[(= ?lstype ?wb)]
)
1 Like
mvy
June 11, 2024, 10:47am
5
That seems to be a good way to do it. I’ve replaced that with a not= operator to avoid the big (not ...)
#+BEGIN_QUERY
{ :title [:b "Pages missing ?t" ]
:query [:find ?pagename
:in $ ?t
:where
[?b :block/properties ?prop]
[?b :block/name _]
[?b :block/original-name ?pagename]
(not [?b :block/journal? true])
[(keyword ?t) ?k]
(not [(get ?prop ?k)])
[(get ?prop :ls-type) ?lstype]
[(keyword "whiteboard-page") ?wb]
[(not= ?lstype ?wb)]
]
:inputs [:current-page]
:view :page-link
}
#+END_QUERY
Not sure if all pages have a :ls-type
property. If they don’t have it, the query will filter them out too. That’s the reason for using the big (not ).
1 Like
Since you are a seasoned programmer, should keep in mind that:
Datalog is even more foreign than Clojure
what @Siferiax said should be understood like this:
You may still move [(keyword "whiteboard-page") ?wb]
out of the (not)
, because it is a constant.
2 Likes
mvy
June 11, 2024, 2:46pm
8
Good point. I kinda filtered out that implicit AND out of my mind.
Also if not all pages have the property, that’s going to break indeed.
Yeah the language is indeed very foreign to say the least, I’m still a bit confused about how things are typed (it seems that there are type at least implicitly), and documentation on the format for logseq itself is not very extensive.
Thank you very much both, that has been very informative and helpful!
1 Like
mvy
June 11, 2024, 4:36pm
10
So I’ve tried this:
#+BEGIN_QUERY
{ :title [:b "ls-type" ]
:query [:find ?pagename ?lstype
:where
[?b :block/properties ?prop]
[?b :block/name _]
[?b :block/original-name ?pagename]
[(get ?prop :ls-type) ?lstype]
]
}
#+END_QUERY
The only thing I got was the :whiteboard-page
. So that’s our answers for have all pages ls-type.
1 Like