←back to thread

115 points graderjs | 1 comments | | HN request time: 0.348s | source
Show context
yodon ◴[] No.25004762[source]
I've often looked for a simple human readable file-based DB-like system like this. Are there other competing packages like this?
replies(6): >>25004905 #>>25004915 #>>25004929 #>>25005021 #>>25005739 #>>25006504 #
1. jitl ◴[] No.25005021[source]
I feel like many static site generators have more-or-less filesystem-as-database. Some are more specialized than others. Many SSGs have standardized around the format of `YAML: Metadata\n\n---\n\nContent`, and expose a query interface over the YAML metadata. But, most static site generators don't generally have create/update API - just a read API.

A reason you don't see much in the "tree of simple files as my DB" space is that the whole point of it is to be trivially simple to understand, and thus, to implement.

Now, with file DBs, it's actually quite important to use atomic writes, so that a crash or concurrent operations don't produce errors. For example, the package posted above can corrupt data if there's concurrent writers to the same data file, because all the writes are non-atomic fs.writeFileSync(). What this database should do instead is write to a tempfile, and then rename the tempfile to replace the destination. That way, you get simple last-write-wins semantics with no possibility of creating invalid JSONs.