Mongokit presentation mongofr-2010

3,464 views

Published on

Slides of my presentation of MongoKIT at MongoFR 2010.

Published in: Technology, News & Politics
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total views
3,464
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
35
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Mongokit presentation mongofr-2010

  1. 1. Enjoy your development Nicolas CLAIRON http://twitter.com/namlook #mongofr
  2. 2. Introducing...
  3. 5. A python ODM for MongoDB
  4. 6. Underlying philosophy
  5. 7. Underlying philosophy light and powerful simple fast
  6. 8. Document class structure
  7. 9. class MyDocument (Document) : Structure Options Descriptors
  8. 10. class MyDocument (Document) : structure = { 'foo' : int , 'bar' : float , 'spam' :{ 'eggs' : [ unicode ], 'blah' : None , } } Options Descriptors
  9. 11. class MyVeryNestedDoc (Document): structure = { '1' :{ '2' :{ '3' :{ '4' :{ '5' :{ '6' :{ '7' : int , '8' :{ '9' : float , } } } } } } } }
  10. 12. class MyDocument (Document) : structure = { 'foo' : unicode , 'bar' : int , 'spam' :{ 'eggs' : [ unicode ], 'blah' : float , } } Options Descriptors
  11. 13. 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
  12. 14. 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
  13. 15. Advantages <ul><li>Great readability
  14. 16. Simple python dict
  15. 17. Pure python types
  16. 18. Nested and complex schema declaration
  17. 19. Fast  : don't instanciate objects
  18. 20. Live update via instrospection
  19. 21. Dynamic keys </li></ul>
  20. 22. 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' }], }
  21. 23. It's all about Pymongo
  22. 24. <ul><li>Built on top of Pymongo
  23. 25. Use the same syntax </li></ul>
  24. 26. <ul><li>Built on top of Pymongo
  25. 27. Use the same syntax </li></ul><ul><li>Easy code migration (pymongo -> MongoKit)
  26. 28. Learn fast
  27. 29. One syntax to rule them all </li></ul>
  28. 30. >>> from mongokit import * >>> con = Connection()
  29. 31. >>> from mongokit import * >>> con = Connection() Pymongo's way >>> doc = con.mydb.mycol.find_one() # very fast ! # doc is a dict instance
  30. 32. >>> 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()
  31. 33. Features
  32. 34. Inheriance / Polymorphism class A (Document) : structure = { 'a' : { 'foo'  : unicode , } } class B (Document) : structure = { 'b' : { 'bar'  : [ float ] , } }
  33. 35. Inheriance / Polymorphism class A (Document) : structure = { 'a' : { 'foo'  : unicode , } } class B (Document) : structure = { 'b' : { 'bar'  : [ float ] , } } class C (A,B) : structure = { 'c' : { 'spam'  : int , } }
  34. 36. 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()
  35. 37. Dot notation class MyDocument (Document) : structure = { 'foo' : unicode , 'bar' : int , 'spam' :{ 'eggs' : [ unicode ], 'blah' : float , } }
  36. 38. Dot notation class MyDocument (Document) : structure = { 'foo' : unicode , 'bar' : int , 'spam' :{ 'eggs' : [ unicode ], 'blah' : float , } } use_dot_notation = True
  37. 39. 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')
  38. 40. Document reference class Comment (Document) : structure = { 'title' : unicode 'body' : unicode , 'author'  : ObjectId, } class User (Document) : structure = { 'login' : unicode , 'name' : unicode , }
  39. 41. Document reference class Comment (Document) : structure = { 'title' : unicode 'body' : unicode , 'author'  : User , } use_autorefs = True class User (Document) : structure = { 'login' : unicode , 'name' : unicode , }
  40. 42. 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()
  41. 43. 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()
  42. 44. 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'] = '…'
  43. 45. i18n class MyDocument (Document) : structure = { 'foo' : unicode , 'bar' : int , } i18n = [ 'foo' ] use_dot_notation = True >>> doc = con.mydb.mycol.MyDocument() >>> doc.set_lang('fr') >>> doc.foo = u'Salut' >>> doc.set_lang('en') >>> doc.foo = u'Hello' >>> doc.save()
  44. 46. <ul><li>Inheritance / Polymorphism
  45. 47. Dot notation
  46. 48. Document auto-reference support (DBRef)
  47. 49. GridFS
  48. 50. I18n support </li></ul>
  49. 51. <ul><li>Inheritance / Polymorphism
  50. 52. Dot notation
  51. 53. Document auto-reference support (DBRef)
  52. 54. GridFS
  53. 55. I18n support
  54. 56. Schema migration
  55. 57. Json export/import </li></ul>
  56. 58. <ul><li>Inheritance / Polymorphism
  57. 59. Dot notation
  58. 60. Document auto-reference support (DBRef)
  59. 61. GridFS
  60. 62. I18n support
  61. 63. Schema migration
  62. 64. Json export/import </li></ul>CAN BE DISABLED
  63. 65. Roadmap and futur plans
  64. 66. <ul><li>Locked fields
  65. 67. Floating fields
  66. 68. Improve atomic saving
  67. 69. Update query validation
  68. 70. Fixtures generation
  69. 71. Structure aliases
  70. 72. RDF export </li></ul>Features planed
  71. 73. <ul><li>All features implemented
  72. 74. Optimizations
  73. 75. Stabilized API
  74. 76. Tested, tested, tested...
  75. 77. Restructured and improved documentation
  76. 78. A new logo ! </li></ul>v1.0
  77. 79. a social trading startup MongoKit in production
  78. 80. Thanks you !
  79. 81. Thanks you ! Questions ? Suggestions ? Comments ? Insults* ? * just kidding

×