際際滷

際際滷Share a Scribd company logo
Enjoy your development Nicolas CLAIRON http://twitter.com/namlook #mongofr
Introducing...
油
油
A python ODM for MongoDB
Underlying philosophy
Underlying philosophy light and powerful simple fast
Document class structure
class   MyDocument (Document)油: Structure Options Descriptors
class   MyDocument (Document)油: structure = { 'foo' :  int , 'bar' :  float , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  None , } } Options Descriptors
class   MyVeryNestedDoc (Document): structure = { '1' :{ '2' :{ '3' :{ '4' :{ '5' :{ '6' :{ '7' : int , '8' :{ '9' : float , } } } } } } } }
class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  float , } } Options Descriptors
class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  float , } } required = [ 'foo' ,  'spam.eggs' ] default_values = { 'spam.blah' 油: 1.0} validators = { 'bar' : lambda  x >0} Options
class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  float , } } required = [ 'foo' ,  'spam.eggs' ] default_values = { 'spam.blah' 油: 1.0} validators = { 'bar' : lambda  x >0} use_dot_notation =  True skip_validation =  True
Advantages Great  readability
Simple  python dict
Pure  python types
Nested  and complex schema declaration
Fast油 : don't instanciate objects
Live  update via instrospection
Dynamic  keys
Dynamic keys class   MobilePhones (Document)油: structure = { 'os'油 : { unicode :[{ 'version' :  float ,  'name' : unicode }], } { 'os'油 : { 'android' :[ { 'version' :  2.2 ,  'name'油 : 'froyo' }, { 'version' :  2.1 ,  'name'油 : 'eclair' } ], 'iphone' :[{ 'version' :  4 ,  'name'油 : 'iOS' }], }
It's all about Pymongo
Built on top of Pymongo
Use the same syntax
Built on top of Pymongo
Use the same syntax Easy code migration (pymongo -> MongoKit)
Learn fast
One syntax to rule them all
>>> from mongokit import * >>> con = Connection()
>>> from mongokit import * >>> con = Connection() Pymongo's way >>> doc = con.mydb.mycol.find_one()  # very fast ! # doc is a dict instance
>>> from mongokit import * >>> con = Connection() Pymongo's way >>> doc = con.mydb.mycol.find_one()  # very fast ! # doc is a dict instance Mongokit's way >>> doc = con.mydb.mycol.MyDocument.find_one() # doc is a MyDocument instance >>> doc.spam.eggs.append(u'foo') >>> doc.save()
Features
Inheriance / Polymorphism class   A (Document)油: structure = { 'a' : { 'foo' 油:  unicode , } } class   B (Document)油: structure = { 'b' : { 'bar' 油: [ float ] , } }
Inheriance / Polymorphism class   A (Document)油: structure = { 'a' : { 'foo' 油:  unicode , } } class   B (Document)油: structure = { 'b' : { 'bar' 油: [ float ] , } } class   C (A,B)油: structure = { 'c' : { 'spam' 油:  int , } }
Inheriance / Polymorphism class   A (Document)油: structure = { 'a' : { 'foo' 油:  unicode , } } class   B (Document)油: structure = { 'b' : { 'bar' 油: [ float ] , } } class   C (A,B)油: structure = { 'c' : { 'spam' 油:  int , } } { 'a' 油: { 'foo' 油:  None }, 'b' 油: { 'bar' 油:  [] }, 'c' 油: { 'spam' 油:  None } } >>> con.mydb.mycol.C()
Dot notation class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  float , } }
Dot notation class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  float , } } use_dot_notation = True
Dot notation class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , 'spam' :{ 'eggs' : [ unicode ], 'blah' :  float , } } use_dot_notation = True >>> doc = con.mydb.mycol.MyDocument() >>> doc.foo = u'the foo' >>> doc.spam.eggs.append(u'bla', u'toto')
Document reference class   Comment (Document)油: structure = { 'title' :  unicode 'body' :  unicode , 'author'油 : ObjectId, } class   User (Document)油: structure = { 'login' :  unicode , 'name' :  unicode , }
Document reference class   Comment (Document)油: structure = { 'title' :  unicode 'body' :  unicode , 'author'油 :  User , } use_autorefs = True class   User (Document)油: structure = { 'login' :  unicode , 'name' :  unicode , }
Document reference class   Comment (Document)油: structure = { 'title' :  unicode 'body' :  unicode , 'author'油 : User, } use_autorefs = True class   User (Document)油: structure = { 'login' :  unicode , 'name' :  unicode , } { 'title'油: 'Hello world油!', 'body'油: 'My first blog post', 'author'油: DBRef(...), } >>> con.mydb.mycol.find_one()
Document reference class   Comment (Document)油: structure = { 'title' :  unicode 'body' :  unicode , 'author'油 : User, } use_autorefs = True class   User (Document)油: structure = { 'login' :  unicode , 'name' :  unicode , } { 'title'油: 'Hello world油!', 'body'油: 'My first blog post', 'author'油: DBRef(...), } >>> con.mydb.mycol.find_one() { 'title'油: 'Hello world油!', 'body'油: 'My first blog post', 'author'油: { 'login'油: 'timy', 'name'油: 'Timy Donzy' } } >>> con.mydb.mycol.BlogPost.find_one()
GridFS support class   MyDocument (Document)油: structure = { 'foo' :  unicode , 'bar' :  int , } grid_fs = { 'files' :[ 'source' ,  'template' ], 'containers' : [ 'images' ], } >>> doc = con.mydb.mycol.MyDocument() >>> doc.fs.source = '...' >>> doc.fs.images['image1.png'] = ''

More Related Content

Mongokit presentation mongofr-2010