Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Proposal: transactions over the Gremlin extension
var tx = new Transaction(); // g.begin();
var v1 = tx.g.addVertex('v1', {name: 'Alice'});
var v2 = tx.g.addVertex('v2', {name: 'Bob'});
tx.g.addEdge(v1, v2, 'knows', {since: '1970'});
// And/or, alternatively:
var tx = new Transaction();
tx.g.addVertex('v1', {name: 'Alice'});
tx.g.addVertex('v2', {name: 'Bob'});
tx.g.addEdge('v1', 'v2', 'knows', {since: '1970'}); // Graph elements references passed as strings

This comment has been minimized.

Copy link

@fattenap fattenap commented Feb 7, 2014

This looks good. My preference would be to allow both styles. The top one provides a reference to the vertex. So if I decide to add more properties before sending the transaction I could. i.e.

var v1 = tx.g.addVertex('v1', {name: 'Alice'});
v1.addProperty('age', 50);

The second one allows for chaining, so I could do something like:

var tx = new Transaction();
  tx.g.addVertex('v1', {name: 'Alice'})
    .addVertex('v2', {name: 'Bob'})
    .addEdge('v1', 'v2', 'knows', {since: '1970'});

I assume that the addEdge method finalises the transaction. I would suggest providing a tx.commit() or when chaining

tx.g.addEdge(v1, v2, 'knows', {since: '1970'}).commit();

so that the user determines when to send the transaction.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment