gremlin-scala icon indicating copy to clipboard operation
gremlin-scala copied to clipboard

how to get or create?

Open triptec opened this issue 9 years ago • 1 comments

How would you do something simple like this? Would be nice to have it in the readme

getOrCreate = { type, id ->
  g.V().hasLabel(type).hasId(id).tryNext().orElseGet{ g.addV(T.id, id, T.label, type).next() }
}

triptec avatar Jul 25 '16 08:07 triptec

that should work, however I'm not really a fan of specifying the id... IMHO that should be left to the database. not sure if it's common enough to have it in the readme on the front page, but a test (e.g. in ElementSpec) would be great - fancy creating a quick PR?

mpollmeier avatar Jul 29 '16 06:07 mpollmeier