coronabytes / dotnet-arangodb

.NET Driver for ArangoDB
Apache License 2.0
67 stars 18 forks source link

Support for optimistic locking using the _rev attribute #21

Closed szJony closed 3 years ago

szJony commented 3 years ago

Would you please add support for optimistic locking using the _rev attribute? Based on my tests, it can be achieved by:

  1. adding 'ignoreRevs=false' parameter to UpdateManyAsync's parameter dictionary, and
  2. extending the 'Revision' field of the documents with attibute.

Possible solution for (1):

diff --git a/Core.Arango/Modules/Internal/ArangoDocumentModule.cs b/Core.Arango/Modules/Internal/ArangoDocumentModule.cs
--- a/Core.Arango/Modules/Internal/ArangoDocumentModule.cs  (date 1617716910120)
+++ b/Core.Arango/Modules/Internal/ArangoDocumentModule.cs  (date 1617716910120)
@@ -187,6 +187,8 @@
         {
             var parameter = new Dictionary<string, string>();

+            parameter.Add("ignoreRevs", "false");
+            
             if (waitForSync.HasValue)
                 parameter.Add("waitForSync", waitForSync.Value.ToString().ToLowerInvariant());

Possible solution for (2):

public abstract class BaseEntity : IBaseEntity {
  ...
  [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
  public string Revision { get; set; }
  ...
}
coronabytes commented 3 years ago

Single / Multi Update and Replace done Multi Delete also Single Get and Delete maybe later (need Rev in If-Match header)

coronabytes commented 3 years ago

all done