Obsidian Dataview
repository·master·Indexed 27 days ago
https://github.com/blacksmithgu/obsidian-dataviewA 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.
What's inside obsidian-dataview
- Every field in Dataview has a specific type that determines how it is rendered, sorted, and which functions can be applied to it. While most fields default to Text, explicitly defining types like Number, Boolean, Date, or Duration allows for complex calculations and specialized query behavior.
Install the Dataview API for development
masterTo develop plugins that interact with Dataview, install the
obsidian-dataviewpackage as a development dependency. You can verify the installed version usingnpm 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.64Define Text and Multiline Text fields
masterThe default type for any field is Text.
For inline fields, a line break signifies the end of the value.
To create multiline text, you must use YAML Frontmatter with the pipe (
|) operator.--- poem: | Because I could not stop for Death, He kindly stopped for me; ---Use Dataview TypeScript types in your own plugin
masterDataview publishes TypeScript typings for its APIs on NPM under the package nameblacksmithgu/obsidian-dataview. You can install these to develop plugins that interact with the Dataview API.Group results in LIST queries
masterWhen using
GROUP BY, a standardLISTquery will only show the group keys. To see the files within those groups, you must specifyrows.file.linkas the additional information.LIST rows.file.link GROUP BY typeExpand arrays with FLATTEN
masterThe
FLATTENcommand 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 likefile.listsorfile.taskswithout complexmap()orfilter()functions.Syntax:
FLATTEN field FLATTEN (computed_field) AS nameExample: To list every author in literature notes as an individual row:
TABLE authors FROM #LiteratureNote FLATTEN authorsTABLE authors FROM #LiteratureNote FLATTEN authorsUse Dataview function vectorization on lists
masterMost 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"]Access fields that conflict with Dataview keywords
masterIf you have a field name that is identical to a Dataview keyword (such as
fromorwhere), you cannot access it directly. Instead, use the specialrowobject to index into the field name.row.from /* Same as "from" */ row.where /* Same as "where" */Customize TABLE column headers
masterUse the
AS <header>syntax to rename columns. If a header contains spaces, wrap it in double quotes (e.g.,AS "File Tags"). This is particularly useful when using calculations as column values.TABLE default(finished, date(today)) - started AS "Played for", file.folder AS Path, file.etags AS "File Tags" FROM #gamesAccess implicit task fields in Dataview queries
masterHow 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 !fullyCompletedIn other query types (LIST, TABLE, etc.)
You must access the fields through the
file.tasksorfile.listscollection using a list function.LIST WHERE any(file.tasks, (t) => !t.fullyCompleted)TASK WHERE !fullyCompletedLIST WHERE any(file.tasks, (t) => !t.fullyCompleted)Use DataviewJS for advanced querying
masterDataviewJS 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));Query by Folders
masterUse the `
TABLE file.ctime, status FROM "projects/brainstorming"