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!
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.
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.
Labels:
datalog,
python,
sqlalchemy
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)
And that's it!
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!
Labels:
posgresql,
programming,
python,
sqlalchemy
Saturday, March 31, 2007
Five things I hate about Python
It's been a meme of late to blog about 5 things you hate about your favorite programming language, in order to qualify you to complain about other languages. (It proves your "objectivity.") What I really wanted to do is blog about things I like about Python, but to go along with the current theme, here is my list of the top 5 things I hate about Python.
Well, there it is. 5 things I hate. Now I can get on to writing about the things I like.
- Lack of support for blocks - I have a bit of an esoteric desire here: I want to use Python-like syntax to build a DSL for compiling into hardware description language, essentially using Python as a macro language on top of the DSL. I want to be able to create my own control structures (hardware_if:...., etc.). Python doesn't let me do this.
- Stdlib organization (or lack thereof) - Maybe this is inevitable, as the stdlib is made up of all sorts of things integrated from other packages, but it would be nice to have something closer to what the C# and Java people rave about in their respective languages.
- Inefficient tail calls (tail recursion) - Maybe not important to too many people since Python has such cool iteration support, but it would be nice to be able to write a tail-recursive function and know that it will be optimized into a loop.
- No "nonlocal" rebinding of functions - This will be fixed in Python 3, which is cool, but it's not there right now. Basically, you can read variables from enclosing scopes right now, but you can't "rebind them", that is, assign the name to a new object. All assignments are either in the local scope (default) or module scope (if you declare the name "global"). And honestly, the main reason I hate this is that it gives Paul Graham one more negative thing to say about Python relative to LISP.
- No dictionary comprehensions - And it's not gonna happen any time soon. List comprehensions are wonderful, and I'd like to build a dict in the same way. I know I can do dict((k,v) for k,v in seq). But I don't like the double-left-paren there. OK, so it's a nit. But wouldn't it be nicer just to say {k:v for k,v in seq}?
Well, there it is. 5 things I hate. Now I can get on to writing about the things I like.
Labels:
python programming
Subscribe to:
Posts (Atom)