New and Improved: DBIx-NoSQL-Store-Manager

January 4th, 2018
perldbix-nosql

New and Improved: DBIx-NoSQL-Store-Manager

A few years ago, I wanted some quick, no fuss way to serialize and persist data encapsulated as Moose objects — a MooSQL database, if you will. In my research, I discovered and bolted my own on top of it.

A few seconds ago, a new release of that latter module has been punted to CPAN. This update adds relationships between those objects. Now, I’m very conscious that I’m slowly creeping toward , but I think (well, whimsically hope) that I managed to balance dwim comfort and dark sorcery.

This being said, let’s an example speak for itself.

The store itself

First up, the main Blog store class. That part is wonderfully boring.

The blog entry

Next we create the class that represents blog entries.

A blog entry has a url (which is also its unique identifier).

And an author, which will also be an object saved in the database.

And can be assigned tags, also saved in the database.

We use two attributes because I want the saved tags to be in fact blog entry/tag pairs (so that’s it’s easy, say, to get all blog entries that have the tag perl), but don’t want the end-user to have to worry about it.

Oh yeah, and content. Let’s not forget some content…

The authors

We also need an Author class. Let’s make it minimalistic: a name and an optional bio.

The tags

Same deal with the tags.

We want to be able to have the same tag associated with different blog entries, so we set the store key to be based on both the tag and the blog’s id, and we index on those two values.

Using it

Setting the store is dead easy. Yes, even if the database didn’t previously exist.

Love you, sqlite. Always did, always will.

You can create objects and put in the store…

… or do it all in one fell swoop.

Once created, it can be used as an attribute for another object.

Or if the object already exist in the db, just use its key.

The object doesn’t exist yet? Pass in a hashref. It will be taken as the arguments of the attribute’s object constructor.

Works with arrays of objects too.

What does the search functionality looks like? Like this.

Right now the objects returned by the search aren’t tied to the store, but it will be fixed soon.

Enjoy!