Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 3. It's waaayyyy more flexible - I can't praise SQLAlchemy enough, it's freaking amazing!

I used SQLAlchemy breifly, but found myself drawn back to the Django ORM (even for non-web based projects) - can someone explain to me why they think SA is better than the Django ORM - I find the latter to be much better.



Mostly because it's a lot more powerful than Django's ORM. Just take a look at the documentation table of contents to get a vague idea: http://www.sqlalchemy.org/docs/

- The support for various class inheritance hierarchies is much more powerful than Django's inheritance.

- You can customize the default JOINs between object relationships very easily.

- You can map objects against arbitrary select statements.

- It has supported multiple databases for a long time now (which only just got added in Django 1.2)

- It supports composite primary keys.

- It implements the unit of work pattern, so you can save entire object graphs without having to explicitly save each individual node. This is a lot more intuitive, IMO.

- It uses an identity map to maintain object consistency. So if you query for the same object in two different queries, the same object is returned (at the Python level).

- The docs are excellent.

I think Django's ORM is fine for simple web apps where the model objects are just used to shuffle data in and out of the database. If you've got complex domain models, or specific database requirements, though, then you'll probably hit a wall where Django won't do what you need, whereas SQLAlchemy probably does.


I would add that the data mapper pattern gives you very fine grained control over what objects and attributes of the object are matched to which tables. So refactoring either your object layer or your table layer is easy to do independently.


Thanks for that list. I guess I haven't run into any of these more "complex" issues yet developing the relatively low scale sites I've been working on. Hopefully some day, the Django ORM would become too much of a time sink for me to consider SA, but in the meantime, I'm gonna be sticking with it just 'cause I find it easier/more intuitive to use :).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: