In Praise of Recfiles
Recfiles let you write and check plain-text notes. They look like this:
%rec: Book
%key: slug
%sort: year month
slug: thinkingexperience
author: H. H. Price
title: Thinking and Experience
year: 1953
publisher: Harvard University Press, Cambridge
slug: yugocaves
author: Dr Neven Krešić
title: Karst I Pećine Jugoslavije
year: 1988
publisher: Naučna Knjiga
slug: metaphysicscontemporaryintro
author: Michael J. Loux
title: Metaphysics: A Contemporary Introduction
year: 1998
publisher: Routledge, London
The Unique Feature Set
Recfile-files are not just notes, each one is a database. The recutils
package comes with the standard database operations: Create, Read,
Update, and Delete.
recsinsto insert records.recselto read records.recsetto change records.recdelto delete records.
You can make the standard queries with recfiles, asking for 'books on Metaphysics released before 1950', or whatever. And you can join queries, asking for 'the address of any publisher of books on Metaphysics which were written before 1950, which remains in business'.
That makes recfiles unique. Lots of databases make joins, but they're not
plain-text, so you can't work with them in a git repo in any meaningful way.
And lots of formats might be called a 'plain-text database' (like CSV, or YAML,
if you want to get abstract).
Recfiles have common features, but the set of features is unique.
Cleaner Syntax than Peers
This ability to write-plain text notes without a 'gotcha' seems strangely rare. Writing the same format in .csv? That won't work for this entry:
Harvard University Press, Cambridge
The comma indicates a new cell, and 'Cambridge' will be transferred to something else, creating a cascade of misinformation. You might switch to putting everything in double-quotes, so your CSV will look like this:
1"thinkingexperience","H. H. Price","Thinking and Experience","1953","Harvard University Press, Cambridge"
But that brings up more 'gotchas': a lot of programs will keep those quotes when processing the CSV, and you can't use the double-quotes inside the field. People use double-quotes a lot, so that's an accident waiting to happen.
Many use json for plain-text data, and it's fine for a lot of structured data, but the reliance on double-quotes means the same problem again, and a few new ones which mean nobody can realistically type out information in json.
Look at all those double-quotes you'd have to type if you actually used this format:
1[
2{
3 "slug": "thinkingexperience",
4 "author": "H. H. Price",
5 "title": "Thinking and Experience",
6 "year": 1953,
7 "publisher": "Harvard University Press, Cambridge"
8}
9{
10 "slug": "yugocaves",
11 "author": "Dr Neven Krešić",
12 "title": "Karst I Pećine Jugoslavije",
13 "year": 1988,
14 "publisher": "Naučna Knjiga",
15},
Seems a shame to use something nobody can actually use when it's not necessary.
Did you spot the mistake?
There's a missing square bracket.
The square brackets don't indicate anything about the books - they're non-functional, but they're standard in json, so you need to get them right.
Also, the last entry doesn't end in a comma.
This last comma also doesn't tell you anything about the books - it only tells the machine that this is not the last item on the list.1
Recfiles are clever enough to count which items are in a set without anyone telling them which one is the last one, and without any square brackets.
Then there's yaml.
It'll let you write easily enough in single file:
1- slug: thinkingexperience
2 author: H. H. Price
3 title: Thinking and Experience
4 year: 1953
5 publisher: Harvard University Press, Cambridge
6- slug: yugocaves
7 author: Dr Neven Krešić
8 title: Karst I Pećine Jugoslavije
9 year: 1988
10 publisher: Naučna Knjiga
Unfortunately you can't transfer that information to other yaml files until you've checked the indentation levels of the file they're coming from, then the file they're going to.
Also this isn't proper yaml according to all versions, and each tool uses a different version.
Sometimes they'll require quotes around words, sometimes they don't.
You can't go far wrong with a recfile line:
text: ' ( o ó } ::] " $
Recfiles will accept any characters at all after that colon and a space. They will not become confused or disheartened by the extra colons, random brackets, mismatched quotes, or strange, invisible characters.
Validation
With recfiles, the relationships between data is just stated at the top. So another recfile might contain lists of essays, including a link to these books:
%rec: Essay
%type: reference rec Book
title: Metaphysics ain't Physics
subject: Philosophy
date: Sun 28 Jun 11:25:27 CEST 2027
reference: thinkingexperience
reference: metaphysicscontemporaryintro
reference: pluralityworlds
That's enough for recfiles to link the essay's references to their publisher
and year of publication. Then you can make sure the date is a valid date and
the title doesn't go on for multiple lines.
Limitations
Recfiles are a relational database, but they can only join one relation at a time. Once you join an article to a publisher, that's that - you attach a relation to the Philosophy class the article came from.2
In larger data sets, you must manually split queries. As an example, I have an nginx log which covers 12 days of access to my websites. Spot the odd-one-out:
aim: Get the file size
query: du -sh access.rec
time: 0.002 seconds
result: 68 megabytes
aim: Count lines in the file
query: wc -l access.rec
time: 0.011 seconds
result: 3,190,721
aim: Search for a word
query: grep -ic petalbot access.rec
time: 0.056 seconds
result: 3650
aim: Count all records
query: recsel access.rec -c
time: 4.193 seconds
result: 290,065
aim: Ask the number of entries containing 'petalbot'
query: recsel access.rec -iq petalbot -c
time: 2.965 seconds
result: 3650
aim: Getting a list of IP addresses where the agent was 'Petalbot'
query: recsel access.rec -G IP -ie "Agent ~ 'petalbot'" -p 'IP,Agent[0]'
time: 67 minutes
aim: Getting a list of IP addresses where the agent was 'Petalbot'
query: recsel access.rec -ie "Agent ~ 'petalbot'" | recsel -G IP -p 'IP,Agent[0]'
time: 4.08 seconds
The split query runs faster that asking recutils to do the lot in a single action.