| Crates.io | krafna |
| lib.rs | krafna |
| version | 0.5.6 |
| created_at | 2025-02-01 13:54:18.834973+00 |
| updated_at | 2025-03-01 09:11:10.720149+00 |
| description | Krafna is a terminal-based alternative to Obsidian's Dataview plugin, allowing you to query your Markdown files using standard SQL syntax. |
| homepage | https://github.com/7sedam7/krafna |
| repository | https://github.com/7sedam7/krafna |
| max_upload_size | |
| id | 1538457 |
| size | 1,310,655 |

Benchmarking on a base Mac mini M4 shows that Krafna can query:
within ~100ms.
Caching is don with bincode. Cache files are not crazy small, but not too big. I might consider compression in the future. (Currently ~250KB for ~100 files) ONLY files that were modified since the last cache are parsed and re-cached. Cache files are stored at:
at com/7sedam7/krafna
Flamegraph is currently pointing to Pod (internal enum struct) deserialization as the biggest bottleneck.
cargo bench has been giving me weird results recently, I'm not expert at using it and did not want to spend too much time on it.
gtime -v might be less precise when it comes to miliseconds, but it seems to give more realistic results.
Run benchmarks: (you can change the number of files that will be generated in bench/query_benchmark.rs)
cargo bench
Run flamegraph: (For a cleaner flamegraph, consider temporarily disabling rayon’s parallelism by replacing par_iter() with iter().)
cargo install flamegraph
cargo flamegraph --root --bin krafna -- 'select file.name, tags from frontmatter_data("../krafna-bench/bench/") where "exampl" in tags'
There are binaries available for Linux, macOS, and Windows under Releases.
cargo install krafna
brew tap 7sedam7/krafna
brew install krafna
Usage: krafna [OPTIONS] [QUERY]
Arguments:
[QUERY] The query to execute
Options:
--select <SELECT>
OVERRIDES SELECT fields from the query with "field1,field2"
--from <FROM>
From option in case you are implementing querying for specific FROM that you don't want to specify every time. This OVERRIDES the FROM part of the query!
--include-fields <INCLUDE_FIELDS>
include SELECT fields with "field1,field2" (prepends them to th front of the SELECT fields in the query)
--find <FIND>
Find option to find all krafna snippets within a dir
--json
Output results in JSON format
-h, --help
Print help
FROM FRONTMATTER_DATA("<path>")<path> and use their frontmatter data as rows.file.name - name of the filefile.path - path to the filefile.created - date when the file was createdfile.accessed - date when the file was last accessedfile.modified - date when the file was last modifiedFROM MD_LINKS("<path>")<path>. Each link is a separate row.file.* - file data same as abovetype - type of the link (inline, wiki)external - true if the link is external (not a local file)url - original url text from markdown filepath - interpreted path to the local file in case link is not external. (relies on that path being within argument specified <path>, otherwise it will be empty)text - text of the linkord - order of the link in the fileFROM MD_TASKS("<path>")
This will find all the tasks in markdown files in the specified <path>. Each link is a separate row.
Tasks in markdown are defined as lines starting with - [ ] or - [x]
FIELDS:
file.* - file data same as above
checked - true if the task is checked (- [x])
text - text of the task
ord - order of the task in the file. If the task is a subtask, there is a '.' and then a number for ordering within a parent task. Nesting is supported.
parent - parent ord of the task in the file. If the task is not a subtask, this will be empty
More functions will come.
No support for AS yet.
LIMIT, OFFSET, JOIN, HAVING, GROUP BY, DISTINCT, etc. are not supported yet.
UPDATE and DELETE are not supported yet.
krafna "SELECT title, tags FROM FRONTMATTER_DATA('~/.notes')"
krafna --find ~/.notes
krafna "SELECT * FROM FRONTMATTER_DATA('~/.notes')" --json
krafna "SELECT * FROM FRONTMATTER_DATA('~/.notes')" --include-fields title,tags
Use with the Perec Neovim plugin for seamless integration.
(not in priority order)
grey-matter-rs for parsing frontmatter data
rayon for parallelizing execution
bincode for binary serialization
CodeRabbit for code reviews
Various AI tools for help with answering questions faster then me searching on Google/StackOverflow