There have been several discussions recently that touched on the usage of TiddlyWiki as a small relational database. While I didn’t chime in on those, that is very much how I tend to use TW. I got to thinking that it would be useful to explain the techniques involved. So I started something. (Boy, do I know how to enjoy a long weekend, huh?!):
https://crosseye.github.io/TW5-SQL_Playground/
There is absolutely no explanatory text yet. That will have to come later… if I decide this is worth pursuing. I found a reasonable SQL Tutorial that comes with its own sample database, and converted that to a JSON collection of tidders, with additional TW-specific fields and CamelCase
replaced by kebab-case
. There are tags/tables for Customer
, Supplier
, Product
, Order
and OrderItem
, with the obvious relationships. Then I created a number of templates to view the data and its interconnections. You can explore that by poking around the Tables
section. (Note that it will take a few hundred milliseconds to expand the menu for Orders
[830 records/tiddlers] , and a few seconds for OrderItem
[2155 of them], but other than that, things should open and display quickly enough.) All those templates are in the $:/_/sql/templates
namespace. All templates, except for Order
tiddlers are quite simple; Order
is meant to look a bit like an invoice. Poke around, have fun. Please tell me if any of it does not seem reasonable.
But the main reason for this is in Examples
. The idea is to have a number of examples of how you would convert SQL statements to somewhat equivalent WikiText. These are either taken directly from the tutorial, or minimally altered from it. Eventually, with explanatory text, this would be a tutorial as well as a list of how-tos. But again, that’s later.
For instance, SQL Where, before any added explanations, looks like this:
SQL
SELECT * FROM Supplier WHERE Country = 'France'
Filter
[tag[Supplier]country[France]]
List Results
Tabular View
city company-name contact-name country fax id phone Paris Aux joyeux ecclésiastiques Guylène Nodier France (1) 03.83.00.62 18 (1) 03.83.00.68 Montceau Escargots Nouveaux Marie Delamare France NULL 27 85.57.00.07 Annecy Gai pâturage Eliane Noz France 38.76.98.58 28 38.76.98.06
The list-versus-tabular views would eventually become quite important, as SQL users expect a list of records, but they would need to come to terms with a list of tiddlers instead. Here we show them both.
I have not gotten to any SQL inserts/updates; they will take a more nuanced approach.
There’s much to do beyond just expanding the contents. I have a lot of duplication to remove; I need to ask the experts for better ways to do some of my templates, and for the most pedagogically sound ways to write the Examples
’ WikiText
I know I will have questions about various specific parts of this, but for now, I would really love to hear first impressions. If expanded out, would this be a useful tool for beginner/intermediate TW users? How understandable are the examples, especially the last few, which are more complex to do in TW? What could I do to improve it? In general, what do you think?
(If you’re GitHub savvy, feel free to give feedback in terms of issues or pull requests on the repository.)
I tend to keep a few copies around:
- The latest released version: https://crosseye.github.io/TW5-SQL_Playground/
- The latest (maybe not yet released) version: https://crosseye.github.io/TW5-SQL_Playground/latest/
- Older versions, by number: https://crosseye.github.io/TW5-SQL_Playground/0.1.0/
At the moment, these all have the same content, of course.