guacamole: an object document mapper for arangodb
TRANSCRIPT
guacamole: an ObjectDocument Mapper forArangoDBMax Neunhöffer
Ruby on Rails Meetup SF, 19 February 2015
www.arangodb.com
Document and Key/Value StoresDocument storeA document store stores a set of documents, which usuallymeans JSON data, these sets are called collections. Thedatabase has access to the contents of the documents.each document in the collection has a unique keysecondary indexes possible, leading to more powerful queriesdifferent documents in the same collection: structure can varyno schema is required for a collectiondatabase normalisation can be relaxedKey/value storeOpaque values, only key lookup without secondary indexes:
=⇒ high performance and perfect scalability1
Graph DatabasesGraph databaseA graph database stores a labelled graph. Vertices andedges are documents. Graphs are good to model relations.graphs often describe data very naturally (e.g. the facebookfriendship graph)graphs can be stored using tables, however, graph queriesnotoriously lead to expensive joinsthere are interesting and useful graph algorithms like “shortestpath” or “neighbourhood”need a good query language to reap the benefitshorizontal scalability is troublesomegraph databases vary widely in scope and usage, no standard
2
The Multi-Model ApproachMulti-model databaseA multi-model database combines a document store with agraph 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 modelsis able to compete with specialised products on their turfallows for polyglot persistence using a single databasequeries can mix the different data modelscan replace a RDMBS in many cases
3
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 transactionsis 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
guacamole
is an Object Document Mapper for Ruby and ArangoDB,builds on the low-level Ruby driver ashikawa-coreimplements the Data Mapper Pattern (and not ActiveRecord)offers Models and Collectionsallows embedding objectsand allows object relations (by using graphs in ArangoDB)
5
Models . . .Make a class into a modelclass 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
. . . and CollectionsCreate a collectionCollections provide the link to the databaseclass 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
Relations between objects— embeddingclass 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
Relations between objects— referencesclass Authorship
include Guacamole::Edge
from :users
to :posts
end
class PostsCollection
include Guacamole::Collection
map do
attribute :author, via: Authorship
end
end
9
URLs
https://www.arangodb.com/
https://github.com/triAGENS/guacamole
https://github.com/triAGENS/ashikawa-core
10