OrientDB is a graph database written in Java, mainly developed by Luca Garulli, AssetData’s CTO.
Why a graph database
Sometimes the relation model isn’t the way you want both to collect and navigate your data: Luca Bonmasser, at the NoSQL day, highlighted it in his talk about anti-patterns in the relational ecosystem.
So, sometimes, in order to:
- improve performances
- mantain a clean data structure
- do DDD right1
you should go for a NoSQL solution: that said, when you also need to store and retrieve a particular data structure, you should work with a graph database.
Oh My Graph
A graph is a really simple entity ( ok, not that simple: I try to outrageously simplify things here ) with vertices and edges.
Edges connect various vertices, and can be directed or undirected: directed connections happen when the edge has an orientation ( like in the case of a person having a car ), undirected when it hasn’t ( like a person being friend of a person, which is a bi-directional connection ).
You use and work with graphs more frequently than what you can actually think: when dealing with trees ( like the ones you tend to solve with Doctrine’s nested sets ) you are basically working with a directed graph with no cycles.
In the database domain, the graph has an additional element, the property: N properties can be assigned to a vertex ( thus any graph storage engine can work as a document-oriented DB ).
Why OrientDB
OrientDB is a NoSQL graph database with an aim: be easy by making you more productive.
So it’s really easy to install and setup: you just need to download the latest release from googlecode ( hope they will move it to GitHub soon ), unzip it and start the server:
1 2 3 4 |
|
Orient is also SQL-friendly, letting you query the database with SQL-like syntax: since everybody knows SQL, you should be able to take confidence with its query language in a few minutes.
It is ACID and can be schema-*; which means that:
- it can be schema-ful, just like a RDBMS
- it can be schema-less, leveraging the power of no-prior knowledge of data’s structure
- it can be schema-mixed, …well, you guessed it!
Another cool thing is that the distribution comes with a pre-defined set of data: so now you are ready to play with graph stuff… but how?
REST in P…DB
I introduce you OrientStudio, the GUI to manage your Orient’s instance.
OrientStudio is a simple tool bundled with Orient’s package, which listens on port 2480 as you start the server, mainly developed in JavaScript, able to let you:
There’s something really cool about OrientStudio: it works, natively, via HTTP, which means that Orient has an HTTP interface to let you manage your graph.
The interface is defined “RESTful”, in the docs: just don’t be finicky and consider it as RESTful as CouchDB ( so definitely not RESTful, but HTTP-loving ).
Orient also works with its binary protocol, which is a looooooot faster than the HTTP one.
OrientDB and PHP
So, what does this have in common with our so-loved scripting language?
We’ll find it out in my next article, where I’ll tell you how to query OrientDb from PHP.
- This is not an academic motivation: DDD is the base of a good OO design ↩