diegogub / aranGO

Golang driver for ArangoDB
Apache License 2.0
125 stars 31 forks source link

Find a way to wrap the ArangoDB transaction system #20

Closed solher closed 8 years ago

solher commented 8 years ago

Following the issue https://github.com/diegogub/aranGO/issues/19.

I tried to write a wrapper at first. But what is hard to do is to wrap the processing you need to do between the two operations.

An example in my case. I need to abstract a create operation: a call to my Create API method creates the nodes but also the edges linking them to their owner user.

So I need a transaction executing:

FOR n IN [{"name":"foo"}, {"name":"bar"}]
INSERT n IN nodes
RETURN NEW

// RETURNS:
// [
//   {
//     "_id": "nodes/47473545749",
//     "_rev": "47473545749",
//     "_key": "47473545749",
//     "name": "foo"
//   },
//   {
//     "_id": "nodes/47472824853",
//     "_rev": "47472824853",
//     "_key": "47472824853",
//     "name": "bar"
//   }
// ]

Then:

FOR l IN [{"_from": "users/5768765876", "_to": "nodes/47473545749"}, {"_from": "users/5768765876", "_to": "nodes/47472824853"}]
INSERT l IN links

How can we do the processing to convert the array of nodes to the array of links between the two requests, without writing Javascript in the transaction ?

Maybe just writing AQL again I suppose...

 FOR n IN [
   {
     "_id": "nodes/47473545749",
     "_rev": "47473545749",
     "_key": "47473545749",
     "name": "foo"
   },
   {
     "_id": "nodes/47472824853",
     "_rev": "47472824853",
     "_key": "47472824853",
     "name": "bar"
   }
 ]
 RETURN {"_from": "users/5768765876", "_to": n._id}

And then links the three queries in JS. Haha why not ?

solher commented 8 years ago

I just pushed the new version of Arangolite including a transaction wrapper ! Check it out and tell me what you think.