Last active
December 12, 2015 10:38
-
-
Save shiroyuki/4760435 to your computer and use it in GitHub Desktop.
The example on how to use ORM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tori.db.document import document | |
| from tori.db.manager import Manager | |
| from tori.db.mapper import link, AssociationType | |
| @document | |
| class Computer(object): | |
| def __init__(self, name): | |
| self.name = name | |
| @link('computer', Computer, association_type=AssociationType.ONE_TO_ONE) | |
| @document | |
| class Person(object): | |
| def __init__(self, name, computer): | |
| self.name = name | |
| self.computer = computer | |
| em = Manager( | |
| name='employee', | |
| document_types=[Person, Computer] | |
| ) | |
| macbook_air = Computer('MacBook Air') | |
| john_smith = Person('John Smith', macbook_air) | |
| em.persist(john_smith) # Cascading on persist by default | |
| em.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment