guacamole: an object document mapper for arangodb

11

Click here to load reader

Upload: max-neunhoeffer

Post on 18-Jul-2015

145 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: guacamole: an Object Document Mapper for ArangoDB

guacamole: an ObjectDocument Mapper forArangoDBMax Neunhöffer

Ruby on Rails Meetup SF, 19 February 2015

www.arangodb.com

Page 2: guacamole: an Object Document Mapper for ArangoDB

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

Page 3: guacamole: an Object Document Mapper for ArangoDB

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

Page 4: guacamole: an Object Document Mapper for ArangoDB

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

Page 5: guacamole: an Object Document Mapper for ArangoDB

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

Page 6: guacamole: an Object Document Mapper for ArangoDB

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

Page 7: guacamole: an Object Document Mapper for ArangoDB

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

Page 8: guacamole: an Object Document Mapper for ArangoDB

. . . 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

Page 9: guacamole: an Object Document Mapper for ArangoDB

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

Page 10: guacamole: an Object Document Mapper for ArangoDB

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

Page 11: guacamole: an Object Document Mapper for ArangoDB

URLs

https://www.arangodb.com/

https://github.com/triAGENS/guacamole

https://github.com/triAGENS/ashikawa-core

10