Thursday, June 4, 2009

SQLAlchemy

SQLAlchemy is the most powerful and flexible database access library for Python. I've made several attempts in the past to get to grips with the module, but I'm finally making progress. SQLAlchemy is probably overkill for my Tom's TV Utility project, which requires a very simple database, but actually using the library for a practical project is definitely helping me to learn it. I decided to avoid SQLAlchemy's Object Relational Mapper (ORM) this time, and stick with the SQL Expression Language which seems to be a lot easier for me to understand. I suspect that is because I already know SQL so the ORM seems very clumsy when I can write the query in my head faster. The Expression Language is like writing SQL in Python so it is easier to convert the query.

The real benefit of SQLAlchemy is database independence. For example, all the unit tests use SQLite but I will use PostgreSQL when I finally get Tom's TV Utility into a usable state (which isn't too far off actually). SQLAlchemy will allow me to make that switch without any fuss. Why use such a powerful database engine for a trivial project? Why not? I already have a PostreSQL server running for SQLedger and several Trac projects so adding more databases is trivial and I get to learn how more about PostreSQL.

No comments:

Post a Comment