Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Guacamole

1,251 views

Published on

This is a talk about Guacamole, an ODM for ArangoDB to be used in Rack-based framework and especially Rails. Dirk gave the talk in London at Skills Matter

Published in: Engineering
  • Be the first to comment

Guacamole

  1. 1. How to make Guacamole or Implement a Data Source Pattern for a Multi-Model NoSQL database 11.8.2014Dirk Breuer/ @railsbros_dirk
  2. 2. How to make Guacamole or Implement a Data Source Pattern for a Multi-Model NoSQL database 11.8.2014Dirk Breuer/ @railsbros_dirk
  3. 3. Data Source Pattern Architectural patterns which drive the way in which the domain logic talks to the database. – Martin Fowler
  4. 4. • Active Record • Data Mapper
 • Table Data Gateway • Row Data Gateway • …
  5. 5. NoSQL Not ACID compliant Big Data Distributed Web Scale ROFL Scale CAP Documents Flexible High Availability
  6. 6. NoSQL Databases • “Not only SQL” • Not one definition • Sometimes just a marketing buzz-fuzz
  7. 7. Classifications • Document-based • Key-Value stores • Graph-based • Column stores • Time series Aggregate-based}
  8. 8. Multi-Model Combine more than one approach within one database system
  9. 9. Guacamole Source: https://en.wikipedia.org/wiki/File:Guacamole.jpg A dip consisting at least of ripe avocados and salt
  10. 10. …and…
  11. 11. gem 'guacamole' An ODM for ArangoDB to be used with Rails and any Ruby application Object Document Mapper
  12. 12. • Open-Source NoSQL database • Multi-Model • Document-based • Graph-based
  13. 13. Why should I use
 ArangoDB in favor of
 <any other document store>? With ArangoDB you can perform joins
 over your documents similar
 to joins in relational databases.
  14. 14. • Powerful query language (AQL) • REST HTTP interface • Embedded V8 to allow custom REST interfaces (Foxx) • Mostly-Memory based with configurable disk synchronization • Support for Transactions • Native driver for most languages
  15. 15. http://docs.arangodb.org/ Everything and more
  16. 16. Before you start building your own ODM
  17. 17. Patterns of Enterprise Application Architecture
  18. 18. Ingredients
  19. 19. 1 Design Goal 1 Data Source Pattern 3 📦 Supporting Libraries 1 Database driver 1 solid Test-Suite 1 📦 Documentation
  20. 20. Design Goal • Support building web applications with Ruby on Rails or other Rack-based frameworks • Focus on easy integration in Views and the general workflow • Reflect the nature of NoSQL in general and ArangoDB in particular
  21. 21. Data Source Pattern
  22. 22. Data Mapper It’s a
  23. 23. + Testability is increased + Separation of Concern + Easier to support database
 features like embedded objects - The average Rails dev is
 used to Active Record - Starting with Data Mapper
 requires more effort
  24. 24. Supporting Libraries
  25. 25. spec.add_dependency 'ashikawa-core' spec.add_dependency 'virtus' spec.add_dependency 'activemodel' spec.add_dependency 'hamster' spec.add_dependency 'activesupport'
  26. 26. Implementation
  27. 27. Just some bits and pieces…
  28. 28. ActiveRecord example class Post < ActiveRecord belongs_to :user has_many :comments end
  29. 29. The Model™ in Guacamole class Post include Guacamole::Model ! attribute :title, String attribute :body, String attribute :comments, Array[Comment] attribute :user, User end
  30. 30. The Collection™ in Guacamole class PostsCollection include Guacamole::Collection ! map do embeds :comments references :user end end
  31. 31. Retrieving Data # Get a user by email UsersCollection.by_example(email: 'p.pie@cupcakes.com') # => #<User:0x007fca7186fc98>
  32. 32. With AQL support # Get a user by name UsersCollection.by_aql('FILTER user.name == @name', name: 'Rainbow Dash') # => #<User:0x007fca7186fc98> http://docs.arangodb.org/Aql/README.html Don’t be scared!
  33. 33. CallbacksExternal
  34. 34. class SecurePonyCallbacks include Guacamole::Callbacks ! # Those will be triggered by the collection before_create :encrypt_password ! def encrypt_password object.encrypted_password = BCrypt::Password.create(object.password) end end
  35. 35. class SecurePony include Guacamole::Model ! callbacks :secure_pony_callbacks ! attribute :encrypted_password, String ! # define a virtual attribute attr_accessor :password end
  36. 36. ActiveModel::Callbacks powered by
  37. 37. Active Model compliance
  38. 38. • Really useful, not only for Rails • A lot of Gems build on top of Active Model • A lot of useful features (i.e. Validations) • Not related to the Active Record pattern
  39. 39. Development with Metrics
  40. 40. Check your Code for • Complexity • Duplication / Similarity • Style • Smells • Sufficient documentation
  41. 41. Caveats Virtus and Circular Dependencies
  42. 42. class Author extend ActiveSupport::Autoload include Guacamole::Model ! autoload :Book, 'models/book' ! attribute :name, String attribute :books, Array[Book] end class Book extend ActiveSupport::Autoload include Guacamole::Model ! autoload :Author, 'models/author' ! attribute :title, String attribute :author, Author end This is not very Ruby
  43. 43. Next Steps
  44. 44. A DSL to create AQL-Queries
  45. 45. Support for Transactions
  46. 46. Support the Graph API Up Next
  47. 47. http://guacamolegem.org Get a Nacho and dip in
  48. 48. Come to us we have cookies animated GIFs.
  49. 49. Sneak Peak
  50. 50. 2014.eurucamp.org/podcast
  51. 51. https://www.arangodb.orghttp://guacamolegem.org @railsbros_dirk Thanks

×