Skip to content

Instantly share code, notes, and snippets.

@dkuppitz
Created August 5, 2016 08:45
Show Gist options
  • Select an option

  • Save dkuppitz/144009e241ce37f8ae290b4845afab58 to your computer and use it in GitHub Desktop.

Select an option

Save dkuppitz/144009e241ce37f8ae290b4845afab58 to your computer and use it in GitHub Desktop.
:remote config alias reset
//system.graph("addresses").drop()
system.graph("addresses").create()
:remote config alias g addresses.g
:remote config timeout max
address_types = [
// type : single
"billing" : true,
"delivery" : false
]
schema.propertyKey('name').Text().single().create()
schema.vertexLabel('person').properties('name').create()
schema.vertexLabel('person').index('byName').materialized().by('name').add()
schema.vertexLabel('address').properties('name').create()
schema.vertexLabel('address').index('byName').materialized().by('name').add()
schema.config().option("graph.allow_scan").set(true)
address_types.keySet().each {
def l = it + "_address"
schema.edgeLabel(l).connection('person','address').create()
}
g.addV('person').property('name','daniel').
addV('person').property('name','gavin').
addV('address').property('name','here').
addV('address').property('name','home').
addV('address').property('name','work').iterate()
setUA = { user, address, type ->
def l = type + "_address"
def create = address_types[type] ? sideEffect(outE(l).drop()).addE(l).to("a") : addE(l).to("a")
g.V().has("address", "name", address).as("a").
V().has("person", "name", user).as("p").
choose(where(out(l).as("a")), outE(l).where(inV().as("a")), create).iterate()
// return current person->address links
g.V().outE().inV().path().by("name").by(label).by("name")
}
setUA "daniel", "home", "billing"
setUA "daniel", "work", "delivery"
setUA "gavin", "work", "delivery"
setUA "gavin", "here", "delivery" // add a 2nd delivery address
setUA "daniel", "here", "billing" // update the existing billing address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment