Build a Datalog query for Logseq DB graphs based on natural language description
Generates optimized Datalog queries for Logseq graphs from natural language descriptions.
/plugin marketplace add C0ntr0lledCha0s/claude-code-plugin-automations/plugin install logseq-expert@claude-code-plugin-automations<query-description>Generate an optimized Datalog query for Logseq DB graphs based on the user's description.
Input: $ARGUMENTS
(pull ?e [*]) - All attributes(pull ?e [:block/title :user.property/rating]) - Specific attributes?title ?author - Multiple values(count ?e) - Aggregations[?b :block/tags ?t] - Tag/class membership[?t :block/title "Book"] - String match[?b :user.property/rating ?r] - Property access[(>= ?r 4)] - Comparisons(not [...]) - Negation(or [...] [...]) - DisjunctionProvide:
| Natural Language | Query Pattern |
|---|---|
| "Find all books" | [?b :block/tags ?t] [?t :block/title "Book"] |
| "Books rated 5 stars" | Add [?b :user.property/rating 5] |
| "Unread books" | Add [?b :user.property/status "To Read"] |
| "Books by Stephen King" | Add [?b :user.property/author "Stephen King"] |
| "Count books per author" | Use (count ?b) with grouping |
## Query: [Description]
### Datalog Query
\`\`\`clojure
[:find (pull ?b [:block/title ...])
:where
...]
\`\`\`
### Explanation
- Line 1: ...
- Line 2: ...
### Usage
**In Query Block:**
\`\`\`
#+BEGIN_QUERY
{:title "..."
:query [:find ...]}
#+END_QUERY
\`\`\`
**In Plugin (JavaScript):**
\`\`\`javascript
const results = await logseq.DB.datascriptQuery(\`...\`)
\`\`\`
### Variations
- To also include X: add `[...]`
- To exclude Y: add `(not [...])`
Generate the query now based on: $ARGUMENTS