Advanced SQLAlchemy
SQLAlchemy is the premier SQL toolkit for Python. SQLAlchemy exposes the full power of SQL while remaining easy to use for the basics, and is flexible enough to work with existing database schemas as well as fresh designs. SQLAlchemy is used in production by leading Python web frameworks Pylons and TurboGears as well as many other web and non-web developers.
This tutorial discusses current data mapping techniques, advanced Query techniques, Session/transaction usage, and maximizing schema usage with SQLAlchemy's event model.
Presenters
Michael Bayer is a software architect in New York City and is the creator of SQLAlchemy.
Jason Kirtland is a software developer based in Portland, Oregon USA and is an author of SQLAlchemy.
Requirements
Python experience: intermediate. You should already have some hands-on experience with Python and be comfortable reading modern Python code.
SQL experience: intermediate. We will use subselects and outer joins as part of the SQL layer.
ORM experience: prior experience with SQLAlchemy or attending the Introduction to SQLAlchemy tutorial is recommended.
For hands-on work, Python 2.4+. Required software will be provided at the session.
Class Outline
Declarative Mapping (30 minutes)
- Initial configuration
- Basic mapping
- Building a many-to-many relation
- Using late-evaluated configuration arguments
- Mapping to a select with declarative
Advanced queries (40 minutes)
- Selecting objects, selecting columns
- Thinking generatively, using values()
- Query as a subquery, from_self()
- New Join Techniques
- Aliases
- Eager loading, contains_eager()
Session Techniques (20 minutes)
- Transaction lifecycle
- Using SAVEPOINT
- Expiring objects, attributes
- Using scoped_session
Inheritance Mapping (40 minutes)
- Single Table Inheritance
- Joined Table Inheritance
- Using with_polymorphic()
- Using as_type()
All About Events (50 minutes)
- MapperExtension
- SessionExtension
- Creating lifecycle event methods
- Using extensions to populate denormalized views
- AttributeExtension
























.