Saturday, February 24, 2018

The 3rd generation of DBIx::DataModel is on CPAN

The 3rd generation of DBIx::DataModel has just been published to CPAN.

DBIx::DataModel is an object-relational mapping (ORM) framework for building Perl abstractions (classes, objects and methods) that interact with relational database management systems. It provides facilities for generating SQL queries, joining tables automatically, navigating through the results, converting values, assembling complex datastructures and packaging the results in various formats.Some of its strong points are :
  1. centralized, UML-style declaration of tables and relationships (instead of many files with declarations such as 'has_many', 'belongs_to', etc.)
  2. limited coupling with the database schema : there is no need to declare every column of every table; DBIx::DataModel only needs to know about tables, associations, primary keys and foreign keys
  3. exposure of database operations like joins, bulk updates, subqueries, etc. The database is not hidden behind object-oriented programming concepts, as some other ORMs try to do, but rather made to explicitly collaborate with the object-oriented layer.
  4. efficiency through a very lightweight infrastructure and through fine tuning of interaction with the DBI layer (prepare/execute, fetch into reusable memory location, etc.)
  5. usage of SQL::Abstract::More for an improved API over SQL::Abstract (named parameters, additional clauses, simplified 'order_by', support for values with associated datatypes, etc.)
  6. clear conceptual distinction between:
    • data sources (tables and joins),
    • database statements (stateful objects representing stepwise building of an SQL query and stepwise retrieval of results),
    • data rows (lightweight hashrefs containing nothing but column names and values)
  7. simple syntax for joins, with the possibility to override default INNER JOIN/LEFT JOIN properties, and with clever usage of Perl multiple inheritance for simultaneous access to the methods of all tables that participate in that join
  8. nested, cross-database transactions
  9. choice between 'single-schema' mode (default, more economical) and 'multi-schema' mode (optional, more flexible, but a little more costly in memory)
  10. detailed documentation exposing not only the surface API but also the internal architecture and design principles
Initially published in 2005, DBIx::DataModel had a 1st refactoring in 2008 and a 2nd refactoring in 2011. Novelties brought by this 3rd refactoring of 2018 are :
  1. architectural simplification : suppression of the ConnectedSource class
  2. new extensible architecture for result kinds produced by calls to select(). Builtin result kinds include various datastructure and file formats ; applications can easily plug additional result kinds.
  3. facilities for switching between several database schemas within the same database connection
  4. method do_after_commit() for registering coderefs to be executed after the end of the outermost transaction.
  5. option join_with_USING for generating joins of shape « Table1 JOIN Table 2 USING (common_key) »
  6. restructuring of the update() method for easier extension by application subclasses
  7. complete revision of the documentation

Saturday, February 17, 2018

Very positive and refreshing articles on Perl 5 -- example for embedded systems

 Michel Conrad recently wrote two very positive articles on Perl 5. Those were relayed on the  LinkedIn Perl group but I haven't seen them on  usual Perl sites, so I share them here in the hope they get propagated better. :

 https://opensource.com/article/18/1/why-i-love-perl-5

https://opensource.com/article/18/1/my-delorean-runs-perl

The second article is very interesting in that it shows an unusual application area for Perl : realtime graphics for a car dashboard ! This reminded me of a very interesting presentation many years ago at the French Perl Workshop 2005 , where we saw an application driving all vehicles on the apron of Port Airport.