Skip to content

Instantly share code, notes, and snippets.

@tiensonqin
Created September 24, 2020 02:19
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiensonqin/b319e19e6a1ef4659f24bb3b71d3d025 to your computer and use it in GitHub Desktop.
Save tiensonqin/b319e19e6a1ef4659f24bb3b71d3d025 to your computer and use it in GitHub Desktop.
Logseq queries example (using properties) and custom view
#+BEGIN_QUERY
{:title [:h2 "Programming languages list"]
:query [:find (pull ?b [*])
:where
[?b :block/properties ?p]
[(get ?p "type") ?t]
[(= "programming_lang" ?t)]]
:view (fn [result]
(when (seq result)
(let [blocks (flatten result)]
[:div.table-wrapper
[:table.table-auto
[:thead
[:tr
[:th {:width "20%"} "Name"]
[:th {:width "20%"} "Creator"]
[:th {:width "60%"} "Description"]]]
[:tbody
(for [{:block/keys [title properties]} blocks]
[:tr
[:td (second (:url (second (first title))))]
[:td (get properties "creator")]
[:td (get properties "description")]])]]])))
}
#+END_QUERY
title
Template

[[]]

:PROPERTIES: :type: programming_lang :creator: :description: :template: programming_lang :END:

title
Test

[[Clojure]]

:PROPERTIES: :type: programming_lang :creator: [[Rich Hickey]] :description: Clojure is a dialect of Lisp, and shares with Lisp the code-as-data philosophy and a powerful macro system. :END:

[[Erlang]]

:PROPERTIES: :type: programming_lang :creator: [[Joe Armstrong]] :description: Erlang is a programming language used to build massively scalable soft real-time systems with requirements on high availability. :END:

@geocine
Copy link

geocine commented Apr 25, 2021

If I want to create table from page properties how do I do it, is there some sort of playground to play with your queries and what available fields are there?

@Creling
Copy link

Creling commented Oct 28, 2022

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