Scala dsls-dissecting-and-implementing-rogue

761 views

Published on

Just a few simple slides for a presentation at Kraków's Scala User Group. The rest of the session is live coding where we reimplement a tiny subset of Rogue, Foursquares MongoDB DSL.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
761
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
11
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Scala dsls-dissecting-and-implementing-rogue

  1. 1. Scala DSLs Dissecting Rogue Konrad Malawski / @ktosopl GDG / PJUG / KSUG / SCKRK ScalaCamp 23.01.2012Wednesday, December 26, 12
  2. 2. Wednesday, December 26, 12
  3. 3. Querying MongoWednesday, December 26, 12
  4. 4. Querying MongoWednesday, December 26, 12
  5. 5. Querying MongoWednesday, December 26, 12
  6. 6. Querying Mongo QL = Plain JSONWednesday, December 26, 12
  7. 7. Querying Mongo QL = Plain JSON JavaScript ConsoleWednesday, December 26, 12
  8. 8. Querying Mongo QL = Plain JSON JavaScript Console Java DriverWednesday, December 26, 12
  9. 9. Querying Mongo QL = Plain JSON JavaScript Console Java Driver Casbah = Scala DriverWednesday, December 26, 12
  10. 10. Querying Mongo QL = Plain JSON JavaScript Console Java Driver Casbah = Scala Driver ... used by RogueWednesday, December 26, 12
  11. 11. Querying Mongo: JS Console APIWednesday, December 26, 12
  12. 12. Querying Mongo: JS db.inventory.find( {} )Wednesday, December 26, 12
  13. 13. Querying Mongo: JS db.inventory.find( {} ) “find all”Wednesday, December 26, 12
  14. 14. Querying Mongo: JS db.inventory.find( { qty: { $gt: 20 } } )Wednesday, December 26, 12
  15. 15. Querying Mongo: JS db.inventory.find( { qty: { $gt: 20 } } ) gt means >=Wednesday, December 26, 12
  16. 16. Querying Mongo: JS db.pople.find( { age: { $gte: 20 }, $or: [ { name: “Ken” }, { name: “Kenshiro” }, { city: “Tokyo” }, ... ] } )Wednesday, December 26, 12
  17. 17. Querying Mongo: JS db.pople.find( { age: { $gte: 20 }, $or: [ { name: “Ken” }, $or may contain any clause { name: “Kenshiro” }, { city: “Tokyo” }, ... ] } )Wednesday, December 26, 12
  18. 18. Querying Mongo: Java Java API (Morhpia)Wednesday, December 26, 12
  19. 19. Querying Mongo: Java ds.find(Employee.class).field("manager").equal(null).get();Wednesday, December 26, 12
  20. 20. Querying Mongo: Java ds.find(Employee.class).field("manager").equal(null).get(); You call this typesafe!?Wednesday, December 26, 12
  21. 21. Mongo with RogueWednesday, December 26, 12
  22. 22. Rogue in Action import com.foursquare.rogue.Rogue._Wednesday, December 26, 12
  23. 23. Rogue in Action Person where(_.age gte 18) limit(100) fetch()Wednesday, December 26, 12
  24. 24. Rogue in Action Code Completion Code Completion Person where(_.age gte 18) limit(100) fetch() Code Completion Code CompletionWednesday, December 26, 12
  25. 25. Rogue in Action Person where(_.age gte “Bazinga”) limit(100) fetch()Wednesday, December 26, 12
  26. 26. Rogue in Action Person where(_.age gte “Bazinga”) limit(100) fetch() Won’t compile - age is IntFieldWednesday, December 26, 12
  27. 27. Rogue in Action Person where(_.age gte 18) limit(100) fetch()Wednesday, December 26, 12
  28. 28. Rogue in Action Person where(_.age gte 18) limit(100) fetch() LimitWednesday, December 26, 12
  29. 29. Rogue in Action Person where(_.age gte 18) limit(100) foreach { p => println(”Name: ” + p.firstName) }Wednesday, December 26, 12
  30. 30. Rogue in Action gte means >= Person where(_.age gte 18) limit(100) foreach { p => println(”Name: ” + p.firstName) }Wednesday, December 26, 12
  31. 31. Rogue in Action Person or( _.where(_.name eqs "Ken"), _.where(_.name eqs "ken") _.whereOpt(Option("Kenshiro")(_.name eqs _)) ) get()Wednesday, December 26, 12
  32. 32. Rogue in Action eqs means Equals Person or( _.where(_.name eqs "Ken"), _.where(_.name eqs "ken") _.whereOpt(Option("Kenshiro")(_.name eqs _)) ) get()Wednesday, December 26, 12
  33. 33. Rogue in Action eqs means Equals Person or( _.where(_.name eqs "Ken"), _.where(_.name eqs "ken") _.whereOpt(Option("Kenshiro")(_.name eqs _)) ) get() Get me one Person.Wednesday, December 26, 12
  34. 34. Rogue in Action eqs means Equals Person or( _.where(_.name eqs "Ken"), _.where(_.name eqs "ken") _.whereOpt(Option("Kenshiro")(_.name eqs _)) ) get() Issue #69: fix in my pull req Get me one Person.Wednesday, December 26, 12
  35. 35. Live HackingWednesday, December 26, 12
  36. 36. Live HackingWednesday, December 26, 12
  37. 37. Live HackingWednesday, December 26, 12
  38. 38. Live Hacking Advanced Stuff.Wednesday, December 26, 12
  39. 39. Live Hacking Advanced Stuff. Fast.Wednesday, December 26, 12
  40. 40. Live Hacking Advanced Stuff. Fast. Ask Questions!Wednesday, December 26, 12
  41. 41. Wednesday, December 26, 12
  42. 42. def links = • Scala Lang http://www.scala-lang.org/ • Scala Koans http://www.scalakoans.org • Blog.Project13.pl - http://www.blog.project13.pl •MongoDB ref - docs.mongodb.org/manual/reference/operators/ • Foursquare Rogue - https://github.com/foursquare/rogue • Java Morphia - http://code.google.com/p/morphia/ • Kraków Scala UG - http://krakowscala.pl / http://scalacamp.plWednesday, December 26, 12
  43. 43. def links = • Scala Lang http://www.scala-lang.org/ • Scala Koans http://www.scalakoans.org • Blog.Project13.pl - http://www.blog.project13.pl •MongoDB ref - docs.mongodb.org/manual/reference/operators/ • Foursquare Rogue - https://github.com/foursquare/rogue • Java Morphia - http://code.google.com/p/morphia/ • Kraków Scala UG - http://krakowscala.pl / http://scalacamp.pl Mailing lists rock!Wednesday, December 26, 12
  44. 44. Thanks! Dziękuję! ありがとう! Konrad Malawski / @ktosopl GDG / PJUG / KSUG / SCKRK ScalaCamp 23.01.2012Wednesday, December 26, 12
  45. 45. Thanks! Dziękuję! ありがとう! I love feedback! <3 Konrad Malawski / @ktosopl GDG / PJUG / KSUG / SCKRK ScalaCamp 23.01.2012Wednesday, December 26, 12

×