Skip to content

Instantly share code, notes, and snippets.

@espeed
Created December 9, 2011 09:22
Show Gist options
  • Save espeed/1450859 to your computer and use it in GitHub Desktop.
Save espeed/1450859 to your computer and use it in GitHub Desktop.
Gremlin YAML Transaction Example
outE: |
g.v($_id).outE($label)
inE: |
g.v($_id).inE($label)
bothE: |
g.v($_id).bothE($label)
outV: |
g.v($_id).outV($label)
inV: |
g.v($_id).inV($label)
bothV: |
g.v($_id).bothV($label)
# vars: data, index_name, keys
create_indexed_vertex: |
import groovy.json.JsonSlurper
def slurper = new JsonSlurper()
keys = data = null
if ('$keys' != 'null')
keys = slurper.parseText('$keys')
if ('$data' != 'null')
data = slurper.parseText('$data')
manager = g.getRawGraph().index()
index = manager.forNodes('$index_name')
g.setMaxBufferSize(0)
g.startTransaction()
vertex = g.getRawGraph().createNode()
for (entry in data.entrySet()) {
if (entry.value == null) continue;
vertex.setProperty(entry.key,entry.value)
if (keys == null || keys.contains(entry.key))
index.add(vertex,entry.key,entry.value)
}
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)
return vertex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment