Skip to content

Instantly share code, notes, and snippets.

@shiroyuki
Last active December 12, 2015 10:38
Show Gist options
  • Select an option

  • Save shiroyuki/4760435 to your computer and use it in GitHub Desktop.

Select an option

Save shiroyuki/4760435 to your computer and use it in GitHub Desktop.
The example on how to use ORM
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