Dev.to AI πŸ€– Ai πŸ‘ 0 πŸ“– 3 min read

Markdown is perfect for (small) databases. Here's how ...

Here's a database: five markdown files about Harry Potter characters, sitting in a folder. No server, no schema. Obsidian shows it as a table I can sort and edit, ten lines of Python query it, and when I ask Claude Code

Markdown is perfect for (small) databases. Here's how ...

Here's a database: five markdown files about Harry Potter characters, sitting in a folder. No server, no schema. Obsidian shows it as a table I can sort and edit, ten lines of Python query it, and when I ask Claude Code in plain English to add Ron, it does.

One file per record

The folder:

characters/
  harry-potter.md
  hermione.md
  malfoy.md
  dumbledore.md
  luna.md

And each file looks like this:

---
name: Harry Potter
house: Gryffindor
status: Alive
creature: Hedwig (Owl)
---

# Harry Potter

The boy who lived. Notes go here, as long as you like.

Characters without a pet get creature: -.

The bit between the --- lines is frontmatter: plain YAML at the top of a markdown file. Almost every markdown tool understands it already.

That's it. You've made a database:

markdown file      β†’  record
frontmatter field  β†’  column
folder             β†’  table

No install, no schema. Want a new column? Add a field to a file.

See it as a table

Open the folder in Obsidian, add a Base, and there it is:

Obsidian table of characters built from frontmatter

Sort by house, filter to the living, edit a cell and it writes straight back to the file. This is the thing Notion is good at, structured fields plus free text in one place. Except here every record is a text file on your own disk, in git if you like, editable in any editor, and still there if Obsidian disappears tomorrow.

Query it with ten lines of Python

You don't need a database engine either. Frontmatter is so simple that a query is a list comprehension:

import pathlib

def records(folder):
    for f in sorted(pathlib.Path(folder).glob("*.md")):
        head = f.read_text().split("---")[1]
        yield dict(line.split(": ", 1) for line in head.strip().splitlines())

alive_with_pets = [r for r in records("characters")
                   if r["status"] == "Alive" and r["creature"] != "-"]

for r in alive_with_pets:
    print(f'{r["name"]:<18} {r["house"]:<11} {r["creature"]}')
Harry Potter       Gryffindor  Hedwig (Owl)
Hermione Granger   Gryffindor  Crookshanks (Cat)

No libraries. (That little parser only handles simple key: value lines and assumes every file has every field; for real YAML use a YAML library. You get the idea.) And for quick questions plain grep works fine:

$ grep -l "house: Gryffindor" characters/*.md
characters/dumbledore.md
characters/harry-potter.md
characters/hermione.md

Or just ask your AI

This is why I think the pattern has gone from "neat trick" to "obviously the right way" in the last year.

AI agents are brilliant at plain files. Point Claude Code or Cursor at the folder and the query language is English:

Which characters are dead? Add Ron Weasley with the same fields.

It reads the files, tells you Dumbledore, and writes characters/ron.md:

---
name: Ron Weasley
house: Gryffindor
status: Alive
creature: Scabbers (Rat)
---

# Ron Weasley

Harry's best friend. Sixth of seven Weasley children.

Run the Python again and Ron shows up. You and the agent are working on the same files, and git shows you exactly what it changed. With Notion you'd be wiring up an API integration before you got this far.

Ok, it's a small database

Hundreds of records, a few thousand, great. Millions of rows, lots of joins, many people writing at once: use Postgres.

But a surprising amount of life fits in a few thousand records: books you've read, recipes, people you've met, projects, a team's decisions, a product catalog, a blog.

I call this the Markdown Database Pattern. The full write-up, plus a step-by-step guide to building one from an empty folder, is on The Way of Markdown: wayofmarkdown.com/markdown-database

What have you got in markdown that's secretly a database? 😎

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.