View
755
Download
0
Category
Preview:
DESCRIPTION
In this talk David will summarize business and technical use cases and introduce Kaiso. He will give a basic overview of how to use it, along with some examples of how one might use it to model complex class hierarchies. This will include some interactive code demonstrations. David will explore the main design goals of the project, the current state of the project, and take a look at what’s ahead on Kaiso’s roadmap.
Citation preview
© Lifealike Limited, 2013.
Kaiso -‐ an object persistence framework for Python and Neo4j
�1
David Szo>enonefinestay
!!!
@szo;en github.com/davidszo;en
© Lifealike Limited, 2013.
Overview
• About onefinestay
• We care about homes
• How we track our homes using Neo4j
• Kaiso demo
�2
© Lifealike Limited, 2013.�3
onefinestay -‐ the unhotel
© Lifealike Limited, 2013.
onefinestay -‐ the unhotel
• Guests live like a local – but with services and ameniNes of a hotel
!
• Members with disNncNve homes earn hassle-‐free income
!
• From just a handful of homes in 2010 to over 1000 homes in 4 ciNes in 2013
�4
© Lifealike Limited, 2013.
How do we do it?
• Provision: Home ⇒ Unhotel
– Clean – Pack away certain items • Make wardrobe space
• Deprovision: Unhotel ⇒ Home
– Clean – Put everything back
�5
© Lifealike Limited, 2013.
We care about our homes. A lot.
• Every home is different
• We require inNmate knowledge
!• For guests: “I can’t walk up stairs”, “Where is the iron?”
• For members: “Please put my fragile vase away before
the guests arrive”
• For us: “How much bed linen do I need to take to this
home for this booking?”
�6
© Lifealike Limited, 2013.
Previous system
• Custom storage soluNon
• Dates back to when we were much smaller
• Problems:
– Siloed
– Hard to query ⇒ denormalised copies
�7
© Lifealike Limited, 2013.
New system
• Want to model our homes – both layout and contents !
• Need flexibility – Our needs are likely to grow and change !
• Track not only objects, but their classes – Ideally treat the taxonomy itself as data
�8
© Lifealike Limited, 2013.
Enter Neo4j
• Handle complex data structures
!
• Ensure extensibility for future needs
!
• Easy to create powerful queries
!
• Makes for a nice conceptual model of our data
�9
© Lifealike Limited, 2013.
Flexibility requirements
• We want to associate informaNon with classes as well as objects – This dishwasher is of make Electropool
– (All) appliances need PAT tesNng !
• Unlike convenNonal object mappers, the taxonomy/class hierarchy needs to be editable by users, and so should be part of the data
�10
© Lifealike Limited, 2013.
Kaiso -‐ an object persistence framework
�11
# (import some stuff)!!class Animal(Entity):! id = Uuid(unique=True)! name = String()! friend_of = Outgoing(FriendOf)!!class Carnivore(Animal): pass!class Herbivore(Animal): pass!!class Penguin(Herbivore):! favourite_ice_cream = String()!!class Lion(Carnivore):! n_siblings = Integer()!
© Lifealike Limited, 2013.
Kaiso: Create some instances
�12
# import types, connect to db!!manager = Manager("http://localhost:7474/db/data/")!!manager.save(Lion)!manager.save(Penguin)!!# create some instances!fred = Penguin(name="Fred")!tom = Lion(name="Tom")!!relation = FriendOf(fred, tom)!!manager.save(fred)!manager.save(tom)!manager.save(relation)
© Lifealike Limited, 2013.
Instances are saved in the graph...
�13
[7] Lion: TomFRIENDOF
[6] Penguin: Fred
© Lifealike Limited, 2013.
... and so is the class hierarchy
�14
FRIENDOF
[1] Type: Animal
[7] Lion: Tom[6] Penguin: Fred
[5] Type: Penguin
[4] Type: Herbivore [2] Type: Carnivore
[3] Type: Lion
ISA ISA
ISAISA
INSTANCEOF INSTANCEOF
© Lifealike Limited, 2013.
Kaiso: Queries based on the type hierarchy
�15
START! Herbivore=node:persistabletype(id="Herbivore"),! Carnivore=node:persistabletype(id="Carnivore")!!MATCH! Carnivore <-[:ISA*]-()<-[:INSTANCEOF]-(carnivore),! Herbivore <-[:ISA*]-()<-[:INSTANCEOF]-(herbivore),!! (herbivore)-[:FRIENDOF]->(carnivore)!!RETURN! "The herbivore",! herbivore.name,! “is a friend of the carnivore",! carnivore.name;!!=> +--------------------------------------------------------------------+!=> | "The herbivore" | "Fred" | "is a friend of the carnivore" | “Tom" | => +--------------------------------------------------------------------+
© Lifealike Limited, 2013.
Thank you
QuesNons?
!
!
Kaiso
github.com/onefinestay/kaiso
!github.com/davidszo;en
@davidszo;en
�16
Recommended