good chemistry is complicated,
and a little bit messy -LW
Announcing: DBIx::PreQL - Less terrible dynamic SQLby TGI (Parson)
|on Sep 19, 2012 at 19:49 UTC||Need Help??|
I just released a new CPAN module, and it is rather nice. Other people have even agreed.
Less terrible dynamic SQL
Managing database interaction is a major part of what software developers doing. We've tried everything from ORM, to programmatic query builders to embedding SQL in our code. Each of these attempts suffer as the complexity of the application and the queries increases.
When what started as a simple script with 2 distinct queries grows into a web hosted service with a full blown AJAX UI, database queries proliferate, and many of them wind up being nearly identical, except for a few lines. Get widgets in stock. Get discontinued widgets in stock. Get widgets of model type foo. Get count of widgets in stock. Get count of each model type of discontinued widgets in stock. Blah blah blah.
To stay sane in the face of all that, we need some automation.
Most existing solutions try to abstract and hide the SQL from the programmer. In my experience this just makes it harder to debug errors when the occur.
What is it?
DBIx::PreQL takes an opposite approach from most SQL automation tools--instead of trying to hide the SQL behind abstraction layers, it adds a tiny bit of markup to existing SQL.
What does it do?
DBIx::PreQL consumes a marked up query and a hash of data. Based on the mark up and the data, each line is considered for inclusion or deletion.
Placeholders and Dependencies:
Given $foo='Foolike', $bar='Barlike', $count_only=0, $page_size=10, $page_number=3, we get the following query and bind vars:
This is a short intro to the feature set. There are some nice tools for working with NULLs, the need to inject literal SQL and lists. Download it, try it and see them for yourself.