DatabaseTemplate
focuses on accessing the database without writing lots of boiler plate codeORMs focus on mapping tables to objects
DatabaseTemplate
does not contest with ORM. The choice we must make is between using SQL and processing result sets or using an ORM.
Note
Before going into detail about ORMs and DatabaseTemplate
, it may be useful to look at a quick example of a popular Python ORM: SQLAlchemy (http://www.sqlalchemy.org). We could have picked any number of ORMs for this demonstration.
from sqlalchemy import * engine = create_engine("sqlite:/tmp/springpython.db", echo=True) metadata = BoundMetaData(engine) article_table = Table('Article', metadata, Column('id', Integer, primary_key=True), Column('title', String()), Column('wiki_text', String())) article_mapper = mapper(Article, article_table) session = create_session(bind_to=engine) articles = session.query(Article)