Skip to content

Instantly share code, notes, and snippets.

@fwbrasil
Created November 22, 2012 17:06
Show Gist options
  • Save fwbrasil/4132151 to your computer and use it in GitHub Desktop.
Save fwbrasil/4132151 to your computer and use it in GitHub Desktop.
Activate graph database support spike
package com.example.foo
import activateExampleContext._
class Person(
var name: String)
extends Vertex
class Knows(
val from: Person,
val to: Person,
var since: Int)
extends Edge[Person, Person]
object Main extends App {
// Create graph
transactional {
val flavio = new Person("flavio")
val felipe = new Person("felipe")
new Knows(flavio, felipe, 2012)
}
// Query
transactional {
val flavio = select[Person].where(_.name :== "flavio").unique
val result = flavio.->[Knows](_.since :>= 2011)
println(result)
}
}
trait Vertex extends Entity {
def ->[E <: Edge[_, _]](f: ((E) => Unit)*) = List()
}
trait Edge[A <: Vertex, B <: Vertex] extends Entity {
val from: A
val to: B
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment