README.md in grumlin-0.21.1 vs README.md in grumlin-0.22.0

- old
+ new

@@ -62,19 +62,24 @@ explicitly specify the provider you use. #### Provider features Every provider is described by a set of features. In the future `Grumlin` may decide to disable or enable -some parts of it's functionality to comply provider's supported features. Currently there is no difference -in behaviour when working with different providers. +some parts of it's functionality to comply provider's supported features. To check current providers supported features use ```ruby Grumlin.features ``` +Current differences between providers: + +| Feature | TinkerGraph |AWS Neptune| +|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|-----------| +| Transactions | Transaction semantic is ignoroed, data is always writen, `tx.rollback` does nothing, an info is printed every time transactions are used with TinkerGraph |Full support + ### Traversing graphs **Warning**: Not all steps and expressions defined in the reference documentation are supported. #### Sugar @@ -238,25 +243,32 @@ - `:single` - `next` - `:none` - `iterate` - `:traversal` - do not execute the query and return the traversal as is `Grumlin::Repository` also provides a set of generic CRUD operations: -- `add_vertex(label, id = nil, **properties)` -- `add_edge(label, id = nil, from:, to:, **properties)` -- `drop_vertex(id)` -- `drop_edge(id = nil, from: nil, to: nil, label: nil)` +- `add_vertex(label, id = nil, start: g, **properties)` +- `add_edge(label, id = nil, from:, to:, start: g, **properties)` +- `drop_vertex(id, start: g)` +- `drop_edge(id = nil, from: nil, to: nil, label: nil, start: g)` and a few methods that emulate upserts: -- `upsert_vertex(label, id, create_properties: {}, update_properties: {}, on_failure: :retry, **params)` -- `upsert_edge(label, from:, to:, create_properties: {}, update_properties: {}, on_failure: :retry, **params)` -- `upsert_edges(edges, batch_size: 100, on_failure: :retry, **params)` -- `upsert_vertices(edges, batch_size: 100, on_failure: :retry, **params)` +- `upsert_vertex(label, id, create_properties: {}, update_properties: {}, on_failure: :retry, start: g, **params)` +- `upsert_edge(label, from:, to:, create_properties: {}, update_properties: {}, on_failure: :retry, start: g, **params)` +- `upsert_edges(edges, batch_size: 100, on_failure: :retry, start: g, **params)` +- `upsert_vertices(edges, batch_size: 100, on_failure: :retry, start: g, **params)` All of them support 3 different modes for error handling: `:retry`, `:ignore` and `:raise`. Retry mode is implemented with [retryable](https://github.com/nfedyashev/retryable). **params will be merged to the default config for upserts and passed to `Retryable.retryable`. In case if you want to modify retryable behaviour you are to do so. +If you want to use these methods inside a transaction simply pass your `gtx` as `start` parameter: +```ruby +g.tx do |gtx| + add_vertex(:vertex, start: gtx) +end +``` + If you don't want to define you own repository, simply use `Grumlin::Repository.new` returns an instance of an anonymous class extending `Grumlin::Repository`. **Usage** @@ -279,9 +291,27 @@ `query` also provides a helper for profiling requests: `MyRepository.new.triangles_with_color(:red, query_params: { profile: true })` method will return profiling data of the results. + +#### Transactions + +Since 0.22.0 `Grumlin` supports transactions when working with providers that supports them: +```ruby +# Using Transaction directly +tx = g.tx +gtx = tx.begin +gtx.addV(:vertex).iterate +tx.commit # or tx.rollback + +# Using with a block +g.tx do |gtx| + gtx.addV(:vertex).iterate + # raise Grumlin::Rollback to manually rollback + # any other exception will also rollback the transaction and will be reraised +end # commits automatically +``` #### IRB An example of how to start an IRB session with support for executing gremlin queries: