Obsidian Dataview

repository·master·Indexed 27 days ago

https://github.com/blacksmithgu/obsidian-dataview

A plugin that treats an Obsidian vault as a queryable database. It provides a custom pipeline-based query language (DQL) and a JavaScript API (DataviewJS) to filter, sort, and extract metadata from Markdown files using YAML frontmatter, inline fields, and implicit file/task properties.

Tokens
21.2K
Snippets
90
Records
154
Agent score
94%

What's inside obsidian-dataview

  1. Install the Dataview API for development

    master

    To develop plugins that interact with Dataview, install the obsidian-dataview package as a development dependency. You can verify the installed version using npm list obsidian-dataview. If you need to ensure you are using a specific version (e.g., 0.5.64), you can install it explicitly.

    Note: Git must be installed on your local system before proceeding.

    npm install -D obsidian-dataview
    
    # To verify version
    npm list obsidian-dataview
    
    # To install a specific version
    npm install obsidian-dataview@0.5.64
  2. Expand arrays with FLATTEN

    master

    The FLATTEN command takes an array in a row and yields one result row for every entry in that array. This is useful for operating on nested lists like file.lists or file.tasks without complex map() or filter() functions.

    Syntax:

    FLATTEN field
    FLATTEN (computed_field) AS name

    Example: To list every author in literature notes as an individual row:

    TABLE authors FROM #LiteratureNote
    FLATTEN authors
    TABLE authors FROM #LiteratureNote
    FLATTEN authors
  3. Use Dataview function vectorization on lists

    master

    Most Dataview functions support "function vectorization." This means if you apply a function to a list of values, the function is applied to each element individually, and the result is a new list of the same length. This works for both single values and lists.

    lower("YES") = "yes"
    lower(["YES", "NO"]) = ["yes", "no"]
    
    replace("yes", "e", "a") = "yas"
    replace(["yes", "ree"], "e", "a") = ["yas", "raa"]
  4. Access implicit task fields in Dataview queries

    master

    How you access task-specific implicit fields depends on the query type:

    In TASK queries

    Tasks are the top-level objects, so you can access fields directly without a prefix.

    TASK
    WHERE !fullyCompleted

    In other query types (LIST, TABLE, etc.)

    You must access the fields through the file.tasks or file.lists collection using a list function.

    LIST
    WHERE any(file.tasks, (t) => !t.fullyCompleted)
    TASK
    WHERE !fullyCompleted
    LIST
    WHERE any(file.tasks, (t) => !t.fullyCompleted)
  5. Use DataviewJS for advanced querying

    master

    DataviewJS provides a high-powered JavaScript API for full access to the Dataview index and custom rendering. It is more powerful than DQL but requires JavaScript knowledge.

    Security Note: JavaScript queries run at the same privilege level as Obsidian plugins and can potentially modify files or make network calls. Use them only with trusted code.

    Example: List all uncompleted tasks:

    dv.taskList(dv.pages().file.tasks.where(t => !t.completed));