Skip to content

Instantly share code, notes, and snippets.

@jbmusso
Created February 6, 2014 23:17
Show Gist options
  • Save jbmusso/8854526 to your computer and use it in GitHub Desktop.
Save jbmusso/8854526 to your computer and use it in GitHub Desktop.
// 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
@fattenap
Copy link

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.

Frank

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