by Romans, 11 Aug 2016
Frankly, I haven't written SQL queries for over a decade. With the majority of my projects being developed in Agile Toolkit, I always had a comfort of a built-in "Relational Models". Even though the implementation of "Models" was a bit lacking in ATK, it was decent and stable.
In early 2016 I have started a stand-alone Open Source project aimed at refactoring and separating "Model" engine from my Agile Toolkit project. Additionally, I felt that some refactoring is over-due. I wanted My data framework to be more intuitive and accessible for new developers.
As you might be frowning right now at the "Model Definition Syntax", this part is inevitable for a database mapping framework. I wanted to note down early on a three significant differences on how Agile Data differentiate from other ORM solutions.
Agile Data is not an ORM. While syntax is similar, you are not facing scalability issues of ORM and don't have to deal with lazy-eager loading. Instead, Agile Data relies on DataSet concept making relationship traversal a little bit more "declarative".
Models in Agile Data are in "Business Domain". This structure can differ significantly from your SQL structure. You can save the same Model in SQL and NoSQL at the same time. Mapping rules can change depending on the capabilities of your database engine and database structure.
To look at the model declaration, see Agile Data Primer application.
A good developer strives to hide the complexity of his code behind a simple-to-use interface. A framework such as Agile Toolkit can help you by providing a scaffolding that you can use for building your own business logic.
Once done, you will be able to use your business models through a simple object-oriented API anywhere inside your application:
$u = new Model_User($db); $u->loadBy('email', 'firstname.lastname@example.org'); $s = $u->ref('System'); $invoices = $s->ref('Client')->ref('Invoice'); echo 'User '.$u['name'].' has access to '. $invoices->action('count')->getOne(). ' invoice records for the total amount of '. $invoices->action('fx', ['sum', 'total']) ->getOne()."\n";
The beauty of a well designed API is ability to fluently traverse objects, reference sets and execute actions across multiple records without resorting to Query Building. The above code can run across multiple database vendors (SQL or NoSQL).
In my next posts, I'll try to focus on individual problem solving with Agile Data, get a copy and read through QuickStart guide.