```Markdown 数据库模式```
Markdown Database Pattern

原始链接: https://wayofmarkdown.com/markdown-database

“Markdown 数据库模式”解决了僵化、专有的内容管理系统(CMS)与非结构化纯文本文件之间的常见冲突。通过利用 Markdown 的元数据(Frontmatter)以及标签、链接和任务等内部元素,你可以将文件目录视为一个灵活且可查询的数据库。 在这种模式下,文件系统充当存储层:Markdown 文件成为记录,元数据字段成为列,目录则充当表。这种方法兼具两者的优势:你既拥有数据所有权、可移植性及版本控制(通过 Git),又能利用 SQL 或 Obsidian 等工具对内容进行筛选、排序和聚合。 该模式非常适合个人知识库、维基或项目日志等规模在万条记录以内的集合。它避免了平台锁定和过度的架构复杂性,证明了你的文件一直以来都包含着一层亟待发掘的结构化、可查询信息。通过转变视角,你现有的文档集合将变成一个轻量级且强大的数据库,并始终处于你的完全掌控之中。

此次讨论围绕“Markdown 数据库模式”展开,该模式使用带有 YAML 元数据(frontmatter)的 Markdown 文件作为轻量且灵活的数据库。 参与者列举了几个当前实现类似概念的工具: * **SilverBullet:** 因其能嵌入查询和脚本,从笔记中生成动态表格和列表而受到称赞。 * **Open Knowledge Format:** 被提及作为一种类似的结构化方法。 * **Notenik:** 被列为另一个利用此模式进行数据管理的应用程序。 * **Astro:** 被指出在其“内容集合”(content collections)功能中使用了类似的设计。 然而,批评者指出,这种方法主要依赖于 YAML 元数据而非 Markdown 本身,认为它本质上是一个“YAML 数据库”。一些人质疑这种模式的必要性,提出结构化数据可以嵌入任何文本格式中,或者建议使用 `recfiles` 等专用工具可能更为合适。总体而言,该讨论反映出人们对于将静态文档转化为可查询、数据驱动的集合越来越感兴趣。
相关文章

原文

Rufus Pollock · begun 2023, maintained since — history

Your filesystem is already a database. Most tools just don't treat it that way.

This is the core insight behind one of the most useful (and underused) patterns in software: treating a collection of markdown files not as documents to be rendered, but as records in a database. Leveraging Markdown's support for "frontmatter", by adopting this pattern you notion-like database experience with content that you control and access on your own hard disk.

Call it the Markdown Database Pattern.


The problem

The standard approach to content management creates a false choice.

On one side: a CMS. You get structured data — fields, types, queries — but your content is locked in a proprietary database, dependent on an admin interface, tied to a platform. The prose is second-class.

On the other side: plain markdown files. You get freedom — plain text, version control, write in any editor, host anywhere. But you give up queryability. You cannot ask "show me everything tagged research written since January." You cannot filter, sort, or aggregate. You have documents, not data.

The Markdown Database Pattern solves this trade-off and gives you the best of both worlds: markdown files with metadata so you own the content, you get free text and you have structured metadata.


The pattern

Name: Markdown Database Pattern

Problem: You want content that is both human-readable rich text and structured queryable data — without locking yourself into a platform or sacrificing the simplicity of plain files.

Solution: Treat a collection of markdown files as a database. Each file is a record. Frontmatter fields are columns. Directories are natural groupings — tables, if you want them to be. Tags, links, and tasks embedded in the document body become additional queryable relations.

The mapping:

Filesystem              Database
──────────────────────────────────
markdown file      →    record
frontmatter field  →    column
directory          →    table
#tag               →    tag relation
[[wikilink]]       →    link relation
- [ ] task         →    task relation

Consequences: You get portability (plain files go anywhere), version control (git works perfectly on plain text), stack independence (no framework required), and full queryability over your collection. You give up scale (this pattern is not for millions of records) and complex relational data (this is not a replacement for a relational database). It is a lightweight database — powerful within its range, and honest about its limits.


An example

A folder of movie notes:

movies/
  return-of-the-jedi.md
  a-new-hope.md
  the-empire-strikes-back.md

Each file:

---
year: 1983
director: Richard Marquand
budget_m: 32.7
tags: [sci-fi, space-opera]
---

# Return of the Jedi

A long time ago in a galaxy far, far away...

That folder is a database. You just need a tool to read the structured layer. Point MarkdownDB at it and you get files and file_tags tables to query:

SELECT * FROM files WHERE year < 1980;
SELECT * FROM files WHERE director = 'George Lucas';
SELECT * FROM file_tags WHERE tag = 'space-opera';

This isn't a live demo — nothing on this page runs the query. The point is that the query is possible: index the folder once and the structured layer is there. The prose is still prose — readable, writable in any editor, stored in git. You did not have to choose.

Seeing it without code

SQL is one way in. The friendlier one: open the same folder in Obsidian and point a Base at it. The frontmatter shows up as a sortable, filterable table, no query language required.

table2

Here it's a handful of character files, rendered as a table. The practical guide covers the tools; the step-by-step tutorial builds one from an empty folder in about 20 minutes.


Where you see this pattern

Once you name it, you start seeing it everywhere.

A personal notes folder with frontmatter is a Markdown Database. A team wiki where every page has a status and owner field is a Markdown Database. A blog where posts carry date, tags, and author metadata is a Markdown Database — it just might not know it yet.

The pattern fits naturally wherever individual records have both a prose side and a data side:

  • Blogs and articles
  • Personal knowledge bases and digital gardens
  • Team wikis and internal documentation
  • Research notes and reading lists
  • Recipe collections, travel logs, project retrospectives

The sweet spot is collections up to roughly ten thousand files. Beyond that, reach for a real database. Below that, this pattern gives you almost everything a database does at a fraction of the complexity — and none of the lock-in.


Implementing it

The pattern can be implemented with surprisingly little code. Parse frontmatter, walk a directory tree, write results to SQLite. A weekend project.

Or use a tool built for it. MarkdownDB indexes a folder of markdown files into SQLite, extracts frontmatter, tags, links, and tasks, and gives you a JavaScript API to query the result. A real queryable database from plain text files in seconds — without giving up the files.


What matters here is not any particular implementation. It is the pattern itself — the recognition that markdown files have a structured layer waiting to be used, and that treating them as database records is a legitimate, powerful, and underexplored design choice.

Plain text has a long future. Markdown is everywhere. The data was always there.

You just needed a name for it.


Build one: Markdown-based databases & catalogs — the practical guide to the tools and conventions, with a step-by-step tutorial at the end.

Colophon

Originally notes in the markdowndb project and elsewhere.

联系我们 contact @ memedata.com