agentleFS
dailyherolddailyherold/skills/logseq-db-query/SKILL.md

logseq-db-query

Skill0 starsChanged 33 days agoMITView on GitHub

Use this skill to query a Logseq DB graph from the command line — especially when the Logseq app is closed, MCP tools are unavailable, or you need a complex cross-entity DataScript query that MCP tools can't express (e.g. filtering by tag AND date range, full-text search with conditions, bulk export). Trigger on: "app is closed, find X in my logseq graph", "without opening logseq, show me...", "find all #Task blocks from last week", "query my graph for blocks matching X and Y", "export my logseq graph", or any read/search request where MCP tools are insufficient or unavailable. Prefer MCP tools (listPages, searchBlocks, etc.) when the app is open and the query is simple. Use this skill for complex queries or offline access. Do NOT use for writes — use MCP upsertNodes instead.

  • Installs packages

The file

Files
SKILL.md

Logseq DB Query Skill

Query a Logseq DB graph directly from SQLite — no app, no MCP, no HTTP API required.

When to use this vs MCP tools

SituationUse
App is open, simple lookup (list pages, get a page)MCP tools
App is closed / MCP unavailableThis skill (CLI)
Complex filter: tag + date range, multi-entity joinThis skill (CLI)
Full-text search across block contentThis skill (search or block-content rule)
Write operationsMCP upsertNodes only

The CLI reads SQLite directly, so it only sees data the app has flushed to disk. If the app is open and you just wrote something, MCP tools will see it; CLI may not.

Prerequisites

  • @logseq/cli installed: npm install -g @logseq/cli
  • A Logseq DB graph (not file-based/markdown)
  • Binary is typically at ~/.npm-global/bin/logseq

Discover Graphs

logseq list           # all local graph names
logseq show GRAPH     # metadata: path, schema version, created date

Graphs live in ~/logseq/graphs/ by default. Use the short name (e.g. agents), not the full path.


Query Command

logseq query 'DATALOG' -g GRAPH
logseq query 'DATALOG' -g GRAPH -p   # expand entity refs to readable values

CRITICAL: Argument Order

The query string must come before -g. Otherwise -g treats it as a second graph name and returns empty results:

# correct
logseq query '[:find ...]' -g agents

# wrong - query string consumed as graph name
logseq query -g agents '[:find ...]'

DataScript Notes

  • CLI automatically adds :in $ % (rules) — do NOT include :in yourself
  • Built-in rules include block-content for full-text matching (see below)
  • Common attributes: :block/title, :block/uuid, :block/journal-day, :block/page, :block/parent, :block/order, :block/tags
  • Journal dates are integers: YYYYMMDD (e.g. 20260310)

Common Query Patterns

Journal page by date:

logseq query '[:find (pull ?p [:block/title :block/uuid]) :where [?p :block/journal-day 20260310]]' -g agents

Blocks on a journal page:

logseq query '[:find (pull ?b [:block/title :block/order]) :where [?b :block/page ?p] [?p :block/journal-day 20260310]]' -g agents

All journal pages:

logseq query '[:find (pull ?p [:block/title :block/journal-day]) :where [?p :block/journal-day _]]' -g agents

Blocks on a named page:

logseq query '[:find (pull ?b [:block/title]) :where [?b :block/page ?p] [?p :block/title "My Page"]]' -g agents

All blocks with a tag:

logseq query '[:find (pull ?b [:block/title :block/uuid]) :where [?b :block/tags ?t] [?t :block/title "Task"]]' -g agents

Blocks with a tag on journal pages in date range (complex — this is the DataScript sweet spot):

logseq query '[:find (pull ?b [:block/title]) :where [?b :block/tags ?t] [?t :block/title "Task"] [?b :block/page ?p] [?p :block/journal-day ?d] [(> ?d 20260303)]]' -g agents

Full-text search using block-content rule:

logseq query '[:find (pull ?b [:block/title :block/uuid]) :where (block-content ?b "nix")]' -g agents

All pages with a tag:

logseq query '[:find (pull ?p [:block/title :block/uuid]) :where [?p :block/tags ?t] [?t :block/title "genesis"]]' -g agents

All tags (classes):

logseq query '[:find (pull ?t [:block/title :block/uuid]) :where [?t :block/tags :logseq.class/Tag]]' -g agents

Entity lookup by UUID:

logseq query '69adf5c2-a62b-42b0-b3e0-5906f37d3f10' -g agents

With readable property values:

logseq query '[:find (pull ?b [*]) :where [?b :block/page ?p] [?p :block/title "My Page"]]' -g agents -p

Search Command

Fast keyword search across :block/title content. Good for quick lookups when you don't need filters.

logseq search 'meeting notes' -g agents
logseq search 'meeting notes' -g agents -l 20   # limit results (default 100)
logseq search 'meeting notes' -g agents -r       # raw output

For full-text search with additional filters (e.g. only on journal pages), use query with the block-content rule instead.


Bulk Export

logseq export-edn -g agents > graph.edn     # full graph as EDN (DataScript format)
logseq export -g agents > graph.json        # full graph as JSON

Useful for offline analysis, backups, or feeding the graph into other tools.


Known Issues

  • CLI only sees data flushed to SQLite — if app is open, very recent writes may not appear
  • search only searches :block/title, not nested properties (use block-content rule in query for deeper search)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.