So as part of this 'Modern Perl' push, I was looking at
KiokuDB for persistence.
I went through the KiokuDB::Tutorial and kept wondering why the
DBI backend did it the way it did: Objects encoded into
JSPON blobs, stored in a single field in an 'entries' table, with "indexing" in a separate table.
I could understand that that probably works well for the BerkeleyDB backend, but putting relational data into a single, essentially unindexable (doing a JOIN from another table with 'index' data doesn't count) blob field is something you really shouldn't be doing in an RDBMS. Basically it moves data validation and management out of the database where it belongs and into the application (A very Rails-ish way of doing things, and that is a bad thing), and making reporting or other analysis of the data impossible without the additional overhead of a Javascript/JSON library.
So while reading I thought of several alternatives that I would have used instead, mostly PostgreSQL-specific (since that is where I live):
- Using PL/Perl and JSON::Any to create a set of functions for inspecting the JSPON data, which could then provide real indexing with PostgreSQL's functional indexes and make reporting possible without too much overhead on the client;
- Storing the data in XML in an XML field and using PostgreSQL's XML/XPath functions for indexing/reporting on the data;
- Creating a custom type for each persisted class and creating a separate table for each class containing an ID field and a field of that specific type;
Upon thinking of the last one on the list, I realised that since CREATE TABLE actually creates a custom type in PostgeSQL, skipping the whole custom type dance, and just creating a database table for each persisted class would work and be the ideal solution. Have a mapping between Moose types and SQL types, create references with foreign keys, provide real indexes on single and multivalued types and enable easy integration with other tools for data reporting and analysis.
Sadly, I doubt that Kioku's DBI backend will change at this stage, so I will probably have to write it myself, and will probably remain PostgreSQL-specific for a while. That is, if I find myself with the need for KiokuDB-level persistence (I usually go from database to code, not the other way round).
Recent Comments