SQL builder library
Posted: Thu Sep 09, 2010 10:17 am
I've been building an OO/Procedural SQL building library that will hopefully assist me in writing advanced SQL queries. SELECT is obviously the trick one, I have tried probably every known OO SQL builder, from the hardcore (entirely OO fluent interface driven) to ones that accept arrays. Mine is somewhere in the middle.
The idea is, is basically you write out the SQL with all possible filters applied, and the framework itself figures out which to drop from the query based on the input.
The framework will then essentially parse the query (although not quite thats already done so I'm working with an parse tree) and based on the values assigned to the query (prepared statements so bind comes into play) will re-construct the above SELECT accordingly. So if you only POST fname to the server and otehrs are NULL or empty, they are left out of the query, thus freeing the developer from having to write out mundane conditional code in the select() methods.
The conditional tests for each filter can be whatever you imagine, but the default is to ignore when NULL or empty which results in a much more declarative SELECT query using an OO/Procedural interface.
So my question becomes, does anyone know of any libraries that support something similar, that I may find interesting to borrow ideas or maybe even collaborate with other developers to help speed development along?
Cheers,
Alex
The idea is, is basically you write out the SQL with all possible filters applied, and the framework itself figures out which to drop from the query based on the input.
Code: Select all
SELECT * FROM persons WHERE (fname = 'Alex' AND lname = 'Gallagher' AND address = '123 Test Street') OR (age = 31 AND gender = 'male')The conditional tests for each filter can be whatever you imagine, but the default is to ignore when NULL or empty which results in a much more declarative SELECT query using an OO/Procedural interface.
So my question becomes, does anyone know of any libraries that support something similar, that I may find interesting to borrow ideas or maybe even collaborate with other developers to help speed development along?
Cheers,
Alex