For some time I’ve been toying with the idea of building my own, custom data access layer. Sure there are plenty out there. Some of them are HUGE (just think PEAR::DB, or ADOdb), which isn’t a bad thing in and of itself if, and only if, they still perform well. I believe ADOdb performs pretty well, but I’ve not actually run the benchmarks to confirm this, so I won’t enter in to that argument. A quick Google search will bring up plenty of articles discussing the pros and cons of Database Abstraction Layers.
The reason I decided to create my own is simple: it will function the way I want it to and it will read the way I want it to. Isn’t that really what matters most? Other than performance, which can be improved over time by minor tweaks and factorizations of the codebase.
The main motivation for my API is in fact inspired by the CodeIgnite Framework, by EllisLab, Inc. What EllisLab has done, is created a fluent interface for their database access layer, which is a fancy way of saying, they let piece your queries together by chaining the various methods of that data access object, one after the other so the entire things reads more fluently.
For example, rather than typing the following:
$dao->where('t.column=1 AND t.collumn!=4');
You could write that as:
->where('t.column=1 AND t.collumn!=4')
I know there isn’t much difference between the two sets of method calls, but I like the latter much better. It reads nicer and you can kinda make out what the query will actually look like, without having to worry to much about syntax and what not.
I’m hoping to be done with the initial API any day now and will likely be putting it to good use in Timeline, so I’ll see how well it performs soon enough. I’m looking forward to seeing whether I can meet all the goals I have set for myself over the next little while.