#markdown #obsidian #sql #cli

bin+lib krafna

Krafna is a terminal-based alternative to Obsidian's Dataview plugin, allowing you to query your Markdown files using standard SQL syntax

9 unstable releases (3 breaking)

new 0.4.1 Feb 16, 2025
0.4.0 Feb 16, 2025
0.3.0 Feb 9, 2025
0.2.2 Feb 5, 2025
0.1.2 Feb 2, 2025

#232 in Text processing

Download history 281/week @ 2025-01-28 478/week @ 2025-02-04 175/week @ 2025-02-11

934 downloads per month

MIT license

1MB
4.5K SLoC

Krafna

codecov

Krafna is a terminal-based alternative to Obsidian's Dataview plugin, allowing you to query your Markdown files using standard SQL syntax.

Features

  • Query Markdown files in a directory using SQL-like syntax
  • Support for frontmatter data extraction
  • Flexible output formats (TSV and JSON)
  • Compatible with Neovim plugin Perec

Installation

Cargo

cargo install krafna

Homebrew

brew tap 7sedam7/krafna
brew install krafna

Usage

Basic Query

krafna "SELECT title, tags FROM FRONTMATTER_DATA('~/.notes')"

Find Files

krafna --find ~/.notes

Output as JSON

krafna "SELECT * FROM FRONTMATTER_DATA('~/.notes')" --json

Include Specific Fields

krafna "SELECT * FROM FRONTMATTER_DATA('~/.notes')" --include-fields title,tags

Syntax Differences from Dataview

  • Uses standard SQL syntax
  • Selection of "table" to query is done with FROM FRONTMATTER_DATA("<path>") function, that makes all md files within a row (their frontmatter data). Currently no other sources and no JOINs. I plan to add them later.
  • Not all Dataview features are implemented yet

Neovim Integration

Use with the Perec Neovim plugin for seamless integration.

Roadmap

(not in priority order)

  • add . support for accesing sub-fields (file.name)
  • * migrate file_name, etc under file (name, path, created, accessed, modified)
  • add default variables (today)
  • * change it so that it does not need to be on every row (can have a general_values hash that can be passed around, and value getters would first check there and then from the source)
  • TODOs
  • Add tests for execution
  • add suport for functions in SELECT
  • add functions
  • * think about which functions to add
  • * DATE("some-date", ) -> new type date
  • * DATEADD()
  • implement val -> val operators
  • UPDATE
  • DELETE
  • add AS to SELECT
  • add querying of TODOs (think of a format similar to todoist)
  • * maybe abstract to query by regex
  • add querying of links between notes
  • think about which other sources would be cool to add
  • add group by

Author

7sedam7

Dependencies

~8–17MB
~224K SLoC