SlideShare una empresa de Scribd logo
1 de 25
Descargar para leer sin conexión
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 (mostly
mine), PHP (mostly Symfony Framework-related) and
Javascript (e.g., Node-AMQP).
T: @shiroyuki FB: juti.noppornpitak
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 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.
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 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.
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 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.
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.
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 association
• Directional
• Unidirectional association (i.e.,
directed graphs)
• Bidirectional (i.e., undirected graphs)
DEMO
Cascades
• Currently available
• Cascade on persist
• Cascade on delete / remove
• Cascade on refresh
• Planned in the later version
• Cascade on merge
• Cascade on detach
DEMO
Transactions... Is that possible?
DEMO
Questions? Thoughts?
MERCI

Más contenido relacionado

Similar a Tori ORM for PyCon 2014

Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
MongoDB
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
S. Bartoli & F. Pompermaier – A Semantic Big Data Companion
S. Bartoli & F. Pompermaier – A Semantic Big Data CompanionS. Bartoli & F. Pompermaier – A Semantic Big Data Companion
S. Bartoli & F. Pompermaier – A Semantic Big Data Companion
Flink Forward
 
Introduction to Python – Learn Python Programming.pptx
Introduction to Python – Learn Python Programming.pptxIntroduction to Python – Learn Python Programming.pptx
Introduction to Python – Learn Python Programming.pptx
HassanShah396906
 

Similar a Tori ORM for PyCon 2014 (20)

Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
Lessons Learned from Building a Multi-Tenant Saas Content Management System o...
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
What is python
What is pythonWhat is python
What is python
 
Introduction To Design Patterns Class 4 Composition vs Inheritance
 Introduction To Design Patterns Class 4 Composition vs Inheritance Introduction To Design Patterns Class 4 Composition vs Inheritance
Introduction To Design Patterns Class 4 Composition vs Inheritance
 
Introduction to Python for Security Professionals
Introduction to Python for Security ProfessionalsIntroduction to Python for Security Professionals
Introduction to Python for Security Professionals
 
Semantic web, python, construction industry
Semantic web, python, construction industrySemantic web, python, construction industry
Semantic web, python, construction industry
 
Python presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, BiharPython presentation of Government Engineering College Aurangabad, Bihar
Python presentation of Government Engineering College Aurangabad, Bihar
 
Dapper: the microORM that will change your life
Dapper: the microORM that will change your lifeDapper: the microORM that will change your life
Dapper: the microORM that will change your life
 
Building OBO Foundry ontology using semantic web tools
Building OBO Foundry ontology using semantic web toolsBuilding OBO Foundry ontology using semantic web tools
Building OBO Foundry ontology using semantic web tools
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
2022-23TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
2022-23TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx2022-23TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
2022-23TYBSC(CS)-PYTHON_PROG_ControlStructure.pptx
 
Practical automation for beginners
Practical automation for beginnersPractical automation for beginners
Practical automation for beginners
 
Python, Django. Why to learn?
Python, Django. Why to learn?Python, Django. Why to learn?
Python, Django. Why to learn?
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Django part 1
Django part 1Django part 1
Django part 1
 
S. Bartoli & F. Pompermaier – A Semantic Big Data Companion
S. Bartoli & F. Pompermaier – A Semantic Big Data CompanionS. Bartoli & F. Pompermaier – A Semantic Big Data Companion
S. Bartoli & F. Pompermaier – A Semantic Big Data Companion
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning StudioIntroduction to Jupyter notebook and MS Azure Machine Learning Studio
Introduction to Jupyter notebook and MS Azure Machine Learning Studio
 
Introduction to Python – Learn Python Programming.pptx
Introduction to Python – Learn Python Programming.pptxIntroduction to Python – Learn Python Programming.pptx
Introduction to Python – Learn Python Programming.pptx
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

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
  • 5. What is Tori Framework?
  • 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.
  • 12. Building Tools • Python 2.7 / 3.3 • PyMongo • Nosetests • Git + GitHub
  • 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.
  • 15. Now, it is the demo time.
  • 16. First, let’s start with the basics.
  • 17. DEMO
  • 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. DEMO
  • 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. DEMO
  • 23. DEMO
  • 25. MERCI