
The full-text functionality of sqlite3 along with the powerful SQL indexing and trigger features allows us to easily keep notes with references in an sqlite3 database. In this document I present a workflow for doing so.
First, let’s examine the pros and cons of this workflow:
Pros:
sqlite3 supports.troff or markdown.sqlite3 CLI and your editor of choice.Cons:
FOREIGN KEY constraints; if you delete a note, the dangling reference in text and in indices remains. You can easily search for and fix them in AFTER INSERT triggers, of course.You can use anything you like as long as it has a basic property: your notes table must have a unique id that you can reference in plain text.
For this demo, I use the bibliothecula schema which has UUIDs for primary keys and allows you to tag or add other arbitrary metadata (and files) to each document. In this model, the document is our notes collection and the files of this document can include plain text ones that are our notes.
The table used for files in bibliothecula is BinaryMetadata; since it’s binary it can also hold plain text data. This is the CREATE statement for BinaryMetadata: