Skip to content

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.

β€” Obsidian Dataview β†—

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

  1. Install BrainDB

  2. Install dependencies

    Terminal window
    pnpm add @braindb/remark-dataview
  3. 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-list
SELECT upper(substr(frontmatter ->> '$.title', 1, 1)), dv_link()
FROM documents
WHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false)
AND frontmatter ->> '$.tags' IS NOT NULL
ORDER BY frontmatter ->> '$.title'
LIMIT 4;
```

Output:

Recently changed

Query:

```dataview list root_class=column-list
SELECT date(updated_at / 1000, 'unixepoch'), dv_link()
FROM documents
WHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false)
AND frontmatter ->> '$.tags' IS NOT NULL
ORDER BY updated_at DESC
LIMIT 3;
```

Output:

Task list

Query:

```dataview list
SELECT dv_link(), dv_task()
FROM tasks JOIN documents ON documents.path = tasks.from
WHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false)
AND frontmatter ->> '$.tags' IS NOT NULL
ORDER BY updated_at DESC, path, tasks.start
LIMIT 2;
```

Output:

Pan and zoom for images

  • Create a Rehype plugin to wrap images in a container ( <figure class="beoe"></figure> ) to avoid creating it on the client side.
  • Do not stretch images if they are smaller than viewport

Tags list

Query:

```dataview list root_class=column-list
SELECT '#' || tags.value as tag, dv_link()
FROM documents, json_each(frontmatter, '$.tags') tags
WHERE (frontmatter ->> '$.draft' IS NULL OR frontmatter ->> '$.draft' = false)
AND frontmatter ->> '$.tags' IS NOT NULL
ORDER BY tag
LIMIT 3;
```

Output: