This is kind of click bait title, because I'm not going to build a relational (not even remotly) in this article. But write about how one can use wiredtiger database like a rdbms.
People don't seem convinced that wiredtiger is the best solution, as of right now, to create database backed application in Guile. Maybe I drink too much of my cool aid. But let me try to convince you again.
This time no fancy algorithms, no, no, no minikaren. We will build a social blogging application using wiredtiger to explicit the fact that it can be used as an RDBMS. So no fancy tricks outside simple RDBMS like tables and indices.
And by the way, if you need more performance or other features in wiredtiger let me know.
wiredtiger can be downloaded using the following command:
To create a guile wiredtiger database you need a Guile REPL.
I don't recall the precise semantic that must be used to describe a relational database schema so I hope the following will do the trick:
That is all.
Another glimpse into wiredtiger
Let's define using theDSL tables and indices for all the above tables. Remember the language looks like the following:
Here is the schema of this simple social blogging app platform:
There is several (!) ways to go on now, I try to make the API simple in the simple case of single threaded applications. So will go on with that API for now.
Now we will create a basic user:
Let's add a blog:
Let's define a small procedure to insert rows to a table quickly:
Let's add a few data to the database
Resolving foreign keys
I forgot to add an index to retrieve users by usernames. So let's assume that we know the identifier associated with usernames likeand .
So we have usernames, let's lists blogs associated with. But first let create a procedure to easily select a single row based on its primary key (or record number).
Let's check that is works correctly:
Now we can easily resolve primary keys to rows. Indices as defined previously only reference the row primary key. This can be configured otherwise for performance tuning reasons but from a cognitive load point of view it's easier to only introduce primary key as index values.
So let's find out what blog hasand :
Similarly we can retrieve the posts associated with a given blog:
Pagination is just a matter of slicing the list of primary keys that you retrieve during index lookup.
That's said sometime you don't have uids at all! And you need to slice the table directly. In this case it might be faster to retrieve all primary keys of the table, slice that list of primary key and thenthe primary keys. But this is only a performance trick!