Section A.1. A Quick Tour of SQLAlchemy


A.1. A Quick Tour of SQLAlchemy

SQLAlchemy, which was first announced in October 2005, is a newer object relational mapper (ORM) than SQLObject. SQLAlchemy is influenced by Hibernate, SQLObject, and others; and can handle a number of cases that are difficult or impossible for SQLObject.

SQLAlchemy's power comes from a few different aspects of its design:

  1. It has an explicit, separate database-independent SQL generation layer.

  2. Its ORM is built with the Data Mapper pattern (we'll talk more about Data Mapper in section A.3).

  3. Its "unit-of-work" approach makes its basic object caching clear.

In addition, SQLAlchemy has some features that SQLObject lacks. It offers Oracle support and better support for compound and noninteger primary keys.

Here is a quick sample to show you what SQLAlchemy feels like. It's a data model for a simple wiki that allows tags to be applied to pages:

After running tg-admin sql create to build the database, we can play with it in an interactive session with tg-admin shell (the sample below was done with IPython installed):

This appendix introduces you to SQLAlchemy and its use within TurboGears. It is not a comprehensive reference or guide to SQLAlchemy. You can find excellent documentation at the official website, www.sqlalchemy.org.

In addition to covering the use of SQLAlchemy in TurboGears, this appendix provides some documentation for the ActiveMapper extension and a guide for migrating an application from SQLObject to SQLAlchemy.




Rapid Web Applications with TurboGears(c) Using Python to Create Ajax-Powered Sites
Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites
ISBN: 0132433885
EAN: 2147483647
Year: 2006
Pages: 202

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net