This is the first draft of the presentation for talk proposal at PyCon 2014. For more information about this framework, please visit https://github.com/shiroyuki/Tori
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
Tori ORM for PyCon 2014
1. Tori Framework and Object
Relational Mapping with MongoDB
Juti Noppornpitak (@shiroyuki)
2. Juti Noppornpitak
Senior Developer at Instaclick Inc. in Toronto
A contributor of some open-source projects in Python (mostly
mine), PHP (mostly Symfony Framework-related) and
Javascript (e.g., Node-AMQP).
T: @shiroyuki FB: juti.noppornpitak
3. What is object relational mapping?
For example, SQLAlchemy.
4. Well, Wikipedia and Google can
help you. But please save the fun
after this talk. :D
6. It is a web framework based on
Tornado Framework.
7. However, nobody knows about this but it has
an object relational mapper for NoSQL
databases... Well, start with MongoDB
8. But why did I go through troubles in
order to create an object relational
mapper for MongoDB in Python?
9. Problems + Motivations
• Develop a database-agnostic ORM for
no-SQL databases.
• Develop an ORM using the Unit of
Work pattern, instead of the popular
Active Record pattern. (Inspired by
Doctrine 2)
• Emphasize on the code portability and
maintainability.
• Emphasize on the minimal class
inheritance. (Inspired by the concept
of pure old Java objects)
• Emphasize on the schema-less
feature of no-SQL databases.
10. Architecture of Tori’s Object
Relational Mapper
• Design Criteria
• Building Tools
• Architecture
11. Design Criteria
•The model class must not extend
from any base classes to reduce the
number of required parent classes
and code overriding.
•Imitate InnoDB's transaction feature
to minimize the number of write
operations on the server and some
capabilities to revert the changes.
•Like any ORMs, handle associations
and cascading automatically.
•Unlike some ORMs, the model
should not enforce the type of the
value of the property, except the
property that is mapped to the
another model.
•Provide a common way to deal with
databases with minimal magic but
good enough to reduce human
errors.
13. Tori ORM Architecture / Entities
• Lightweight object
• Normal object (no extension required)
• Many entities can be mapped to the same collection.
• The constructor is used to initially set the data.
• Entity class can extend other entity classes as well as any entity classes.
• All public properties (without leading underscores) are mapped to the respective
documents.
• Use decorators to set up the metadata, including the associations and indexes.
14. Tori ORM Architecture / Entity
Manager
• Centralize the access point to the ORM functionality.
• Manage pseudo-transactional write operations to optimize the
database interactions.
• Similar to SQLAlchemy and Doctrine, internally use a UnitOfWork
to track all loaded references.
20. Cascades
• Currently available
• Cascade on persist
• Cascade on delete / remove
• Cascade on refresh
• Planned in the later version
• Cascade on merge
• Cascade on detach