object relational mapping pattern - using sql object
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.TRANSCRIPT
![Page 2: Object Relational Mapping Pattern - using Sql Object](https://reader036.vdocuments.mx/reader036/viewer/2022073102/559d14941a28abd1018b471d/html5/thumbnails/2.jpg)
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.
![Page 3: Object Relational Mapping Pattern - using Sql Object](https://reader036.vdocuments.mx/reader036/viewer/2022073102/559d14941a28abd1018b471d/html5/thumbnails/3.jpg)
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).
![Page 4: Object Relational Mapping Pattern - using Sql Object](https://reader036.vdocuments.mx/reader036/viewer/2022073102/559d14941a28abd1018b471d/html5/thumbnails/4.jpg)
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/.
![Page 5: Object Relational Mapping Pattern - using Sql Object](https://reader036.vdocuments.mx/reader036/viewer/2022073102/559d14941a28abd1018b471d/html5/thumbnails/5.jpg)
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
![Page 6: Object Relational Mapping Pattern - using Sql Object](https://reader036.vdocuments.mx/reader036/viewer/2022073102/559d14941a28abd1018b471d/html5/thumbnails/6.jpg)
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.
![Page 7: Object Relational Mapping Pattern - using Sql Object](https://reader036.vdocuments.mx/reader036/viewer/2022073102/559d14941a28abd1018b471d/html5/thumbnails/7.jpg)
An Example
• Object Model