Skip to Main Content
Essential SQLAlchemy
book

Essential SQLAlchemy

by Rick Copeland
June 2008
Intermediate to advanced content levelIntermediate to advanced
230 pages
6h 29m
English
O'Reilly Media, Inc.
Content preview from Essential SQLAlchemy

Chapter 9. Elixir: A Declarative Extension to SQLAlchemy

This chapter describes Elixir, a module developed to automate some of the more common tasks in SQLAlchemy by providing a declarative layer atop “base” or “raw” SQLAlchemy. This chapter also describes the various extensions to Elixir that provide features such as encryption and versioning.

Introduction to Elixir

The Elixir module was developed as a declarative layer on top of SQLAlchemy, implementing the “active record” pattern described in Chapter 6. Elixir goes out of its way to make all of the power of SQLAlchemy available, while providing sensible default behavior with significantly less code than “raw” SQLAlchemy. This chapter describes versions 0.4 and 0.5 of Elixir, corresponding to the 0.4 version of SQLAlchemy. Differences between versions 0.4 and 0.5 are discussed in the upcoming sidebar, Differences Between Elixir 0.4 and 0.5.”

So, what exactly does Elixir do? Well, consider a simple product database. In SQLAlchemy, we might set up the products, stores, and prices with the following code:

product_table = Table( 'product', metadata, Column('sku', String(20), primary_key=True), Column('msrp', Numeric)) store_table = Table( 'store', metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(255))) product_price_table = Table( 'product_price', metadata, Column('sku', None, ForeignKey('product.sku'), primary_key=True), Column('store_id', None, ForeignKey('store.id'), primary_key=True), Column('price', Numeric, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PostgreSQL

Learning PostgreSQL

Salahaldin Juba, Achim Vannahme, Andrey Volkov
Practical PostgreSQL

Practical PostgreSQL

Joshua D. Drake, John C. Worsley
PostgreSQL

PostgreSQL

Korry Douglas, Susan Douglas
Learning PostgreSQL 11 - Third Edition

Learning PostgreSQL 11 - Third Edition

Christopher Travers, Andrey Volkov

Publisher Resources

ISBN: 9780596516147Supplemental ContentErrata Page