SQLAlchemy has a release (and a declarative layer)
by Kevin Dangoor
SQLAlchemy, which was announced a couple months back and has been busy in svn, has now had its first release. Congrats to Mike Bayer on that! SQLAlchemy is an object-relational database mapper that uses the data mapper pattern. This is in contrast to SQLObject and ActiveRecord which use the active record pattern. Also interesting for SQLAlchemy, is that Jonathan LaCour’s declarative layer effectively gives you active record-style mapping. The data mapper pattern works well for more complicated databases or bigger databases because it lets you be more explicit about what you want to pull from the database and how you want it to show up in your objects. That flexibility also makes it more complex for simpler tasks. That’s why I think that Jonathan’s ActiveMapper strikes a nice compromise.
From what I’ve seen, SQLAlchemy looks good, mainly because it seems to give more of the power of SQL than something like SQLObject. Are there any plans for integrating SQLAlchemy or other database layers into TurboGears? The model level definitely seems to be the least tightly coupled of all the components in TurboGears, so it *seems* like it would be straightforward to have pluggable models like we have pluggable templates. Just my $.02.
Actually, TurboGears 0.9 includes a fair amount of SQLObject integration: basic database connection handling is the obvious one, but there’s also implicit database transaction support and the ability to go straight from your model to web pages (via the FastData package) plus CatWalk and Model Designer in the Toolbox.
It’s also worth noting that TurboGears will continue to have one recommended way of doing things for which a solution is provided.
Ah, I see. Then ignore what I said
I’ve been working with 0.8.8 until 0.9 comes out. Sounds like there’s a great deal of momentum behind 0.9. I’m definitely looking forward to exploring the new features. (Though I’m not quite ready for the bleeding-edge from SVN… )
I have to admit I’d be a lot more interested in TG if it used a better ORM tool.
I’ve written a preliminary guide to using SQLAlchemy with TurboGears:
http://trac.turbogears.org/turbogears/wiki/UsingSqlAlchemy
I probably didn’t put enough emphasis on the lack of implicit transactions (you have to explicitly commit, even in the controller) and the fact that there are two layers of transaction-like behavior: The Unit of Work level and a planned transaction system level.
I maintain that fastdata support should be rather simple and admit to never having used CatWalk or ModelDesigner.
One more thing, Jonathan has posted an example and a request for help over on his blog:
http://cleverdevil.org/computing/35/declarative-mapping-with-sqlalchemy
I like the way SQLAlchemy does things and it already has Oracle support. Which means if it was integrated with TG I could use TG now.
Karl, that’s a fantastic overview. Any chance of augmenting it to include the ActiveMapper code? I know ActiveMapper isn’t final yet, but it would be wonderful to see how to get that working…
On the positive side, it wouldn’t be that hard to create a TG plug in that automatically commits the unit of work after a successful request…
And I promise to get a SqlAlchemy based Identity Provider going soon…
where can I found a SqlAlchemy patch for fastdata?