Guacamole is an object document mapper for Ruby that builds on the ArangoDB driver ashikawa-core. It implements the data mapper pattern to provide models and collections for working with ArangoDB documents and graphs. Models validate attributes and are saved to collections, which provide access to the database. Relations between objects can be represented through embedding or references using ArangoDB graphs.
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
guacamole: an Object Document Mapper for ArangoDB
1. guacamole: an Object
Document Mapper for
ArangoDB
Max Neunhöffer
Ruby on Rails Meetup SF, 19 February 2015
www.arangodb.com
2. Document and Key/Value Stores
Document store
A document store stores a set of documents, which usually
means JSON data, these sets are called collections. The
database has access to the contents of the documents.
each document in the collection has a unique key
secondary indexes possible, leading to more powerful queries
different documents in the same collection: structure can vary
no schema is required for a collection
database normalisation can be relaxed
Key/value store
Opaque values, only key lookup without secondary indexes:
=⇒ high performance and perfect scalability
1
3. Graph Databases
Graph database
A graph database stores a labelled graph. Vertices and
edges are documents. Graphs are good to model relations.
graphs often describe data very naturally (e.g. the facebook
friendship graph)
graphs can be stored using tables, however, graph queries
notoriously lead to expensive joins
there are interesting and useful graph algorithms like “shortest
path” or “neighbourhood”
need a good query language to reap the benefits
horizontal scalability is troublesome
graph databases vary widely in scope and usage, no standard
2
4. The Multi-Model Approach
Multi-model database
A multi-model database combines a document store with a
graph database and a key/value store.
Vertices are documents in a vertex collection,
edges are documents in an edge collection.
a single, common query language for all three data models
is able to compete with specialised products on their turf
allows for polyglot persistence using a single database
queries can mix the different data models
can replace a RDMBS in many cases
3
5. is a multi-model database (document store & graph database),
is open source and free (Apache 2 license),
offers convenient queries (via HTTP/REST and AQL),
including joins between different collections,
configurable consistency guarantees using transactions
is memory efficient by shape detection,
uses JavaScript throughout (Google’s V8 built into server),
API extensible by JS code in the Foxx Microservice Framework,
offers many drivers for a wide range of languages,
is easy to use with web front end and good documentation,
and enjoys good community as well as professional support.
4
6. guacamole
is an Object Document Mapper for Ruby and ArangoDB,
builds on the low-level Ruby driver ashikawa-core
implements the Data Mapper Pattern (and not ActiveRecord)
offers Models and Collections
allows embedding objects
and allows object relations (by using graphs in ArangoDB)
5
7. Models . . .
Make a class into a model
class Pony
include Guacamole::Model
attribute :name, String
attribute :color, String
validates :color, presence: true
end
p = Pony.new
p.color = :pink
# => "pink"
p.type = "Earthpony"
# => ["Earthpony"]
p = Pony.new
p.valid?
# => false
p.errors[:color]
# => ["can't be blank"]
6
8. . . . and Collections
Create a collection
Collections provide the link to the database
class PoniesCollection
include Guacamole::Collection
end
p = Pony.new(name: "Paul")
PoniesCollection.save p
# => #<Pony:0x124 ...>
p.name = "Tom"
PoniesCollection.save p
ponies = PoniesCollection.by_example(color: 'green')
.limit(10)
# => #<Guacamole::Query:0x1212 ...>
ponies.first
# => #<Pony:0x90u81 ...>
7
9. Relations between objects — embedding
class Comment
include Guacamole::Model
attribute :text, String
end
class Post
include Guacamole::Model
attribute :title, String
attribute :body, String
attribute :comments, Array[Comment]
end
class PostsCollection
include Guacamole::Collection
map do
embeds :comments
end
end
8
10. Relations between objects — references
class Authorship
include Guacamole::Edge
from :users
to :posts
end
class PostsCollection
include Guacamole::Collection
map do
attribute :author, via: Authorship
end
end
9