Friday, June 06, 2008

Essential SQLAlchemy Ships

Well, I finally got my hands on the first (that I know of) copy of my book Essential SQLAlchemy. You can get it from Amazon using the link below. (Disclaimer: this is my affiliate link. Hey, it's my blog after all, right? ;-) )


I think the book turned out well, although I was a little surprised at how thin it was. 200 or so pages seems like a lot more when you're writing (or reading) it. Many thanks go out to all who put up with me during the writing of the book, including my coworkers, editors, reviewers, and my amazing wife Nancy. (Not to mention my son Matthew, who was born during the proofreading phase of the book. I wisely delayed my proofreading until we all got home from the hospital.)

Anyway, here is a picture of me with the book at work taken by my coworker Jenny Walsh on her iPhone:


I'll try to post some more about SQLAlchemy at some point. It really is a fantastic library. Thanks go to Mike Bayer and all the other contributors for writing it!

Edit 7:16pm June 6, 2008
As I have been reminded by Noah, I will be presenting a talk on SQLAlchemy for the July 10th Python Atlanta user group PyAtl, followed by a book signing. I should have a few books available there to sell, or you can (obviously) bring our own. You can RSVP for the meeting at the PyAtl Meetup Site.

Wednesday, March 12, 2008

Essential SQLAlchemy Available on Amazon

I thought I'd give a heads up to the readers of this blog that my book on SQLAlchemy, Essential SQLAlchemy, being published by O'Reilly, is now available for pre-order on Amazon.com. Amazon lists the availability date as June 15, and I have no information beyond that.

P.S. In other news, I also thought I'd mention that I would have loved to give a talk at PyCon (on SQLAlchemy or something else), but I am reluctant to travel for a few weeks due to the upcoming arrival of my first child, just in case he comes early (he is due on April 9th). So maybe next year -- to everyone who's going, have fun!

Thursday, February 14, 2008

PyAtl BloxAlchemy Talk

I gave a talk at the Atlanta Python user group last night on a project I've been working on called BloxAlchemy. BloxAlchemy is bascially a SQLAlchemy-inspired library that targets a logical database known as LogicBlox instead of a SQL database. I've uploaded the slides here, if you're interested.

Update 2/16/08: The video of the talk is now available on Google video here. If you're going to watch the talk, I'd recommend keeping the slides opened in a separate window while watching, since I make a lot of references to code on the slides that isn't in the video.

Monday, January 07, 2008

Cascading DROP TABLE with SQLAlchemy

A little quirk that can get you if you're using SQLAlchemy to create and drop your database is that PostgreSQL doesn't allow you to drop a table that has other tables referring to it via FOREIGN KEY constraints. PostgreSQL has a DROP TABLE ... CASCADE command that supports this (and drops all the dependent tables) but there's no easy way to use the DROP TABLE ... CASCADE statement. It's not too hard to make it available, though.

It turns out, however, that SQLAlchemy has a nice, pluggable database dialect system that is fairly simple to update. One part of this dialect system is a "SchemaDropper". So to cascade the DROP TABLE statements, I just created the following SchemaDropper (derived from the existing PostgreSQL PGSchemaDropper) and installed it as the default PostgreSQL dialect schemadropper. (Most of the code is copied from the base SchemaDropper class in sqlalchemy.sql.compiler)


from sqlalchemy.databases import postgres

class PGCascadeSchemaDropper(postgres.PGSchemaDropper):
def visit_table(self, table):
for column in table.columns:
if column.default is not None:
self.traverse_single(column.default)
self.append("\nDROP TABLE " +
self.preparer.format_table(table) +
" CASCADE")
self.execute()

postgres.dialect.schemadropper = PGCascadeSchemaDropper


And that's it!