Tori Framework and Object
Relational Mapping with MongoDB
Juti Noppornpitak (@shiroyuki)
Juti Noppornpitak
Senior Developer at Instaclick Inc. in Toronto
A contributor of some open-source projects in Python (mos...
What is object relational mapping?
For example, SQLAlchemy.
Well, Wikipedia and Google can
help you. But please save the fun
after this talk. :D
What is Tori Framework?
It is a web framework based on
Tornado Framework.
However, nobody knows about this but it has
an object relational mapper for NoSQL
databases... Well, start with MongoDB
But why did I go through troubles in
order to create an object relational
mapper for MongoDB in Python?
Problems + Motivations
• Develop a database-agnostic ORM for
no-SQL databases.
• Develop an ORM using the Unit of
Work pat...
Architecture of Tori’s Object
Relational Mapper
• Design Criteria
• Building Tools
• Architecture
Design Criteria
•The model class must not extend
from any base classes to reduce the
number of required parent classes
and...
Building Tools
• Python 2.7 / 3.3
• PyMongo
• Nosetests
• Git + GitHub
Tori ORM Architecture / Entities
• Lightweight object
• Normal object (no extension required)
• Many entities can be mappe...
Tori ORM Architecture / Entity
Manager
• Centralize the access point to the ORM functionality.
• Manage pseudo-transaction...
Now, it is the demo time.
First, let’s start with the basics.
DEMO
Associations
• Relational
• One-to-one association
• One-to-many association
• Many-to-one association
• Many-to-many asso...
DEMO
Cascades
• Currently available
• Cascade on persist
• Cascade on delete / remove
• Cascade on refresh
• Planned in the lat...
DEMO
Transactions... Is that possible?
DEMO
Questions? Thoughts?
MERCI
Upcoming SlideShare
Loading in …5
×

Tori ORM for PyCon 2014

539 views

Published on

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

Published in: Technology
  • Be the first to comment

Tori ORM for PyCon 2014

  1. 1. Tori Framework and Object Relational Mapping with MongoDB Juti Noppornpitak (@shiroyuki)
  2. 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. 3. What is object relational mapping? For example, SQLAlchemy.
  4. 4. Well, Wikipedia and Google can help you. But please save the fun after this talk. :D
  5. 5. What is Tori Framework?
  6. 6. It is a web framework based on Tornado Framework.
  7. 7. However, nobody knows about this but it has an object relational mapper for NoSQL databases... Well, start with MongoDB
  8. 8. But why did I go through troubles in order to create an object relational mapper for MongoDB in Python?
  9. 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. 10. Architecture of Tori’s Object Relational Mapper • Design Criteria • Building Tools • Architecture
  11. 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.
  12. 12. Building Tools • Python 2.7 / 3.3 • PyMongo • Nosetests • Git + GitHub
  13. 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. 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.
  15. 15. Now, it is the demo time.
  16. 16. First, let’s start with the basics.
  17. 17. DEMO
  18. 18. Associations • Relational • One-to-one association • One-to-many association • Many-to-one association • Many-to-many association • Directional • Unidirectional association (i.e., directed graphs) • Bidirectional (i.e., undirected graphs)
  19. 19. DEMO
  20. 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
  21. 21. DEMO
  22. 22. Transactions... Is that possible?
  23. 23. DEMO
  24. 24. Questions? Thoughts?
  25. 25. MERCI

×