SQL Builder
| From: | Lukas Smith | Date: | Fri, 12 Nov 2004 14:07:47 +0000 |
| Subject: | SQL Builder | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-34358@lists.php.net to get a copy of this message | ||
Hi,
Some may have heard the rumors about LiveUser getting a huge iternal overhaul. Part of this overhaul is to dynamically build the SQL in the Admin backend. Using OO to represent the different entities didnt seem feasible enough, since we want more control over what is actually possible (as well as being able to also better accomodate non DBMS backends). We also wanted a clear API and we also wanted performance. More importantly we didnt want people to have to know that much about the internal structure (they still need to know a bit though). Maybe we were just not that happy about how other SQL Builders handle joins in PEAR.
Eitherway I wrote up a general idea of how things should go and yesterday and today I wrote up the following code in a 2 hour hacking session. The current code automatically determines what tables need to be join based on the field the users requests as well as the filters, orders etc. This has the severe limitation that field names need to be unique by concept for lack of a better word. Specifically this means that for example you cant have a field called "name" that is used in one table to denote the name of a right and in another table denote the name of a group. However this problem can be alliviated calling the name fields something like "right_name" or "group_name".
Another limitation is in the filter handling. Currently I am just using simple key value pairs so I can only "AND" filters using "=" or "IN". Turning the value into an array would allow also handling stuff like "<,
, LIKE" etc and OR. Adding support for grouping filters using parenthesis or allowing other fields to be used as value would probably require turning filters into objects (Propels criterias come to mind here).Anyways here is the code: http://www.backendmedia.com/LiveUser/Simple.phps regards, Lukas