Thursday, March 1, 2007

Database libraries

Monday - Wednesday was spent redoing the database access layer. I'd been using's built in database libraries, but that's not suitable for the production site, because it uses a global database connection. If we need to move to multiple databases, it'll be a royal mess.

I considered using SQLAlchemy and spent much of last week researching that, but IMHO it's overkill. I don't need a full object/relational mapping layer; I'm quite happy with SQL and don't need to write my SQL statements in Python. So I ended up writing a thin wrapper on top of raw DBAPI classes. It basically provides convenience methods similar to PEAR DB for querying (using SQL), along with direct SQL generation for INSERT, UPDATE, and DELETE.

Am very grateful for unit tests. They let me change everything globally and let me know instantly where I'd broken things. Just need to flesh them out; a couple pages don't yet have tests.

This morning, I got a comment box to appear on the game page. Wrote the database schema for comments on the subway. I'll integrate it in and write the code when I get home.