Drupal Databases: The future is now

Submitted by Larry on 24 August 2008 - 1:58pm

OK, I admit it. I'm not the most active Cubs fan around. I wouldn't say I'm a fair weather fan (the Cubs don't have fair weather that often) but I don't follow the team that closely. Perhaps I should start doing so, because I think this may be our year.

No, it's not because this is the 100th anniversary of when the Cubs last won the World Series. It's because the Databases: TNG patch for Drupal 7 has finally landed.

And there has been much rejoicing.

The new database layer is a major milestone for me, as it is far and away the largest endeavor I've ever undertaken for Drupal. It's also the longest running; I trace it all the way back to DrupalCon Sunnyvale and this patch, when its main purpose was to help encourage people to move to PHP 5. After a slight detour it was reborn as an API revamp, and by the time it was done had a laundry list of new features. Some of my personal favorites include:

  • Type-safe queries on all databases.
  • Database targeting for Master/slave replication and more features yet to come.
  • Dynamic, chainable, fluent-API INSERT/UPDATE/DELETE query builders. Never write an INSERT query yourself again!
  • Merge queries. I didn't even know the term when I started, but they're actually quite sexy. :-)
  • A compact SELECT query builder in core. At long last! (And there's still more features to come on it.)
  • Transaction support.
  • Alter hooks for dynamic queries. db_rewrite_sql(), your days are numbered!
  • And more!

Full documentation will be forthcoming, probably as a follow-on to my DrupalCon Szeged presentation on the new database API this coming Friday. Good grief, that's only 5 days away! (You're coming to Szeged, right?)

If you can't wait that long, Use the Source, Luke! The new database code is extensively documented inline. Most code files are actually more DocBlocks than they are executable code. I'm not even sure if api.module will be able to handle it. :-)

And there's plenty of code, too. Even with the patch not converting all of core to the new DB API, the final patch weighed in at no less than 387 KB, not the largest patch ever (the original FAPI still claims that title) but probably in the top 10. It does, however, claim the crown as longest-running patch ever. The final commit came in on comment #338 (with lots of follow-on comments). That makes it the longest issue thread ever by a wide margin, and that's not even counting its predecessor issues. The next longest thread, More secure password hashing, topped out at "only" 272 comments. Oof! Let's make this another record that doesn't get broken for a while and save our own sanity. :-)

Of course, there's plenty more work to be done. With the main patch in, I've stepped forward as Database System Maintainer for Drupal 7 and beyond. That doesn't mean I'll be writing everything, of course (or at least I dearly hope not). It means I need your help to follow-through on the next steps. I've compiled a list of the most important "next steps" issues. If you want to take on on, please do so! I'll be watching the issue queue and trying to review everything I can.

I also want to take a moment to thank a few people. Those who have seen me in IRC recently know that I've been grumbling about the patch not getting the attention or help I had hoped, but to be fair there were a number of people in the issue queue who were helping where they could, and the patch could not have happened without them. I in particular want to single out Barry Jaspan, who wrote the initial PostgreSQL driver (which ferreted out all sorts of design flaws in the process) and of course the infamous chx. Ironically he's the one who pushed me to go all-out on the OOP front, which turned out to be one of the best decisions we made. He was also the steadiest reviewer, sounding board, and patch roller throughout the whole process. Thanks, chx! We couldn't have done it without you.

That's it from me for now. Next stop, Szeged, Hungary. I'll see if I can blog as I go this time, but after the last three DrupalCons I am somehow not convinced that will happen. :-)

I've gotten used to stuff like Cake or Hibernate. I don't think I've written a query in years and would love to not have to. good stuff. keep it up