Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save spmallette/4f6af914d712d590eb32b95024e37ace to your computer and use it in GitHub Desktop.
Save spmallette/4f6af914d712d590eb32b95024e37ace to your computer and use it in GitHub Desktop.
gremlin> g = TinkerGraph.open().traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.withSideEffect('onCreate', [name:'a', created: 123]).
......1> withSideEffect('onMatch', [updated: 321]).
......2> V().has('name','a').fold().
......3> coalesce(unfold().as('v').sideEffect(select('onMatch').unfold().as('kv').
......4> select('v').
......5> property(select('kv').by(keys), select('kv').by(values))),
......6> addV().as('v').sideEffect(select('onCreate').unfold().as('kv').
......7> select('v').
......8> property(select('kv').by(keys), select('kv').by(values))))
==>v[0]
gremlin> g.V().elementMap()
==>[id:0,label:vertex,created:123,name:a]
gremlin> g.withSideEffect('onCreate', [name:'a', created: 123]).
......1> withSideEffect('onMatch', [updated: 321]).
......2> V().has('name','a').fold().
......3> coalesce(unfold().as('v').sideEffect(select('onMatch').unfold().as('kv').
......4> select('v').
......5> property(select('kv').by(keys), select('kv').by(values))),
......6> addV().as('v').sideEffect(select('onCreate').unfold().as('kv').
......7> select('v').
......8> property(select('kv').by(keys), select('kv').by(values))))
==>v[0]
gremlin> g.V().elementMap()
==>[id:0,label:vertex,created:123,name:a,updated:321]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment