15 Apr 2009 22:24
DAO for Propel with Named Query support.
Tony Bibbs <tony <at> tonybibbs.com>
2009-04-15 20:24:13 GMT
2009-04-15 20:24:13 GMT
Ok, I've managed to get around to polishing off a DAO implementation for Propel. What makes this implementation unique is it adds a powerful alternative to Criteria in what is dubbed Named Queries. Named Queries are nothing more than XML files containing SQL queries that are given names. Those names can then be used to execute a specific query. Why, would anybody want this? - It's a good middle ground between portability and the desire to prevent having to learn a new way to write queries (e.g. Criteria or something like HQL for you Hibernate fans). - Allows a single SQL query to be reused in multiple parts of your application. - It keeps your application clean by taking explicit SQL calls out of your code - Allows for quick regression testing. Because SQL is centralized into one (or more) files you can easily write a unit test to regression test all your queries after a database upgrade. - Just like Criteria it returns Propel objects OR raw data. How does it work? - First, all Named Query files are validated against the included XSD - XML is compiled into a PHP array for faster, subsequent access. - Calls to a specific query cause the query to be pulled from the array and then ran through a PDO prepared statement. There are two parts to this implementation: 1) Generator (optional): we add a new PEER builder class that is DAO aware. The only thing this builder does special is it adds a __callStatic() method (new to PHP 5.3) that knows how to call named queries by name (example later). To use it simply change set the(Continue reading)
RSS Feed