SELECT pizza.name
FROM Person as person
JOIN Likes as likes ON person.id = likes.person
JOIN Pizza as pizza ON likes.pizza = pizza.id AND
WHERE person.id = 1
vs. gremlin
g.V(1).out("likes").values("name")
(friends of friends)^n
Property Graph
Query languages
Cypher
MATCH (Actor {name: 'Woody Allen'})
-[:ACTED_IN]->(movie:Movie)
WHERE movie.year > 2010
RETURN movie
import gremlin.scala._
implicit val graph = TinkerGraph.open.asScala
schema
define once, use everywhere
object PersonNode {
val label = "person"
val name = Key[String]("name")
val age = Key[Int]("age")
}
object LikesEdge {
val label = "likes"
val howMuch = Key[Double]("howMuch")
}
arrow syntax
val alice = graph + (person, name -> "alice", age -> 35)
val tonno = graph + (pizza, name -> "tonno")
alice --- likes --> tonno
alice --- (likes, howMuch -> 3) --> tonno
case classes
case class Person(@id id: Option[Int] = None,
name: String,
age: Option[Int])
val alice = graph + Person(name = "alice", age = Some(35))
alice.toCC[Person] // Person with id set