Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oakfang/graph-tx

Isolated Transactions for the graph-core graph
https://github.com/oakfang/graph-tx

Last synced: 20 days ago
JSON representation

Isolated Transactions for the graph-core graph

Awesome Lists containing this project

README

        

# graph-tx

Isolated Transactions for the @xgraph/core graph

## Usage

```js
const createTransaction = require('graph-tx');
const g = require('./graph');
const tx = createTransaction.bind(null, g);

tx(({ graph, commit }) => {
graph.setVertex(...);
commit(); // mark tx as done
});

tx(({ graph }) => {
graph.setVertex(...);
// auto commit on successful termination of transaction
});

tx(({ graph, rollback }) => {
graph.setVertex(...);
rollback(); // rollback changes and mark as done
});

tx(({ graph }) => {
graph.setVertex(...);
throw new Error(); // auto rollback on errors
});

tx(({ graph, commit, rollback }) => {
// do stuff
}, {
onCommit() {
// do stuff after commit
},
onRollback(err) {
// do stuff after rollback
}
});
```