Object Relational Mapping Pattern - using Sql Object

Preview:

DESCRIPTION

Relational databases and OO memory models use different paradigms. Mapping between one and the other is fiddly work so an auto-mapping tool like Sql Object (python framework) can help enormously.

Citation preview

SQLObject

Object-Relational Mapper (ORM)for Python

Presented by Andy Bulka

abulka@netspace.net.au

Impedance Mismatch

• Relational databases and OO memory models use different paradigms.

• Management likes databases.

• Programmers like OO models.

• Mapping between one and the other is fiddly work.

The Basic ORM Solution

• A class is a table.

• An attribute on a class is a column in a table.

• Automatic mapping code in your classes so that setting attributes on objects has side effects (it changes the database).

SQLObject

• Provides a strong database abstraction, allowing cross-database compatibility e.g. SQLLite, MySQL, firebird, maxdb, postgres, sybase.

• Possibly use sqlserver via mxODBC.

• SQLRelay http://sqlrelay.sourceforge.net/.

SQLObject Joins

• One-to-one

• One-to-many

• Many-to-many

• (Something which many ORMs do not have.) The join system is also intended to be extensible

Inheritance

• SQLObject supports inheritance

• The inherited table does not have to repeat the attributes of the table it inherits from – just adds new attributes.

• SQLObject will look after the mappings and for each OO memory instance, creates an entry in both tables.

An Example

• Object Model

Recommended