Obsidian Dataview
Dataview is a live index and query engine over your personal knowledge base. You can add metadata to your notes and query them with the Dataview Query Language to list, filter, sort or group your data. Dataview keeps your queries always up to date and makes data aggregation a breeze.
Dataview is a plugin for Obsidian β. However, we can build our own βDataviewβ with BrainDB:
- Use remark-code-hook β to catch all code blocks with the
dataview
language - Treat the code as SQL and execute wiht BrainDB
- Translate the result to MDAST (or HTML)
Installation
-
Install BrainDB
-
Install dependencies
Terminal window pnpm add @braindb/remark-dataview -
Configure Astro. See note about Rehype Plugins for Code.
astro.config.mjs import remarkDataview from "@braindb/remark-dataview";import { getBrainDb } from "@braindb/astro";const bdb = getBrainDb();await bdb.ready();export default defineConfig({markdown: {remarkPlugins: [[remarkDataview, { bdb }]],},});
Examples
Alphabetical index
Query:
```dataview list root_class=column-listSELECT upper(substr(frontmatter ->> '$.title', 1, 1)), dv_link()FROM documentsWHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false) AND frontmatter ->> '$.tags' IS NOT NULLORDER BY frontmatter ->> '$.title'LIMIT 4;```
Output:
Recently changed
Query:
```dataview list root_class=column-listSELECT date(updated_at / 1000, 'unixepoch'), dv_link()FROM documentsWHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false) AND frontmatter ->> '$.tags' IS NOT NULLORDER BY updated_at DESCLIMIT 3;```
Output:
2025-03-29
Task list
Query:
```dataview listSELECT dv_link(), dv_task()FROM tasks JOIN documents ON documents.path = tasks.fromWHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false) AND frontmatter ->> '$.tags' IS NOT NULLORDER BY updated_at DESC, path, tasks.startLIMIT 2;```
Output:
- Handle non-HTML links (images, PDFs)
- Handle footnotes
Tags list
Query:
```dataview list root_class=column-listSELECT '#' || tags.value as tag, dv_link()FROM documents, json_each(frontmatter, '$.tags') tagsWHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false) AND frontmatter ->> '$.tags' IS NOT NULLORDER BY tagLIMIT 3;```
Output:
#code-fences