Created
November 22, 2012 17:06
-
-
Save fwbrasil/4132151 to your computer and use it in GitHub Desktop.
Activate graph database support spike
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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