Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing properties to Post, Put and Patch document query objects #460

Merged
merged 4 commits into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions arangodb-net-standard/DocumentApi/Models/OverwriteModes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace ArangoDBNetStandard.DocumentApi.Models
{
/// <summary>
/// Defines values for document overwrite modes
/// Possible value for <see cref="PostDocumentsQuery.OverwriteMode"/>
/// </summary>
public static class OverwriteModes
{
/// <summary>
/// If a document with the specified _key value exists already,
/// nothing is done and no write operation is carried out.
/// The insert operation returns success in this case.
/// This mode does not support returning the old document
/// version using <see cref="PostDocumentsQuery.ReturnOld"/>.
/// When using <see cref="PostDocumentsQuery.ReturnNew"/>, null
/// is returned in case the document already existed.
/// </summary>
public const string Ignore = "ignore";

/// <summary>
/// If a document with the specified _key value exists
/// already, it is overwritten with the specified document
/// value. This mode is also used when no overwrite mode
/// is specified but the <see cref="PostDocumentsQuery.Overwrite"/>
/// flag is set to true.
/// </summary>
public const string Replace = "replace";

/// <summary>
/// If a document with the specified _key value exists
/// already, it is patched (partially updated) with the
/// specified document value. The overwrite mode can be
/// further controlled via the
/// <see cref="PostDocumentsQuery.KeepNull"/> and
/// <see cref="PostDocumentsQuery.MergeObjects"/>
/// parameters.
/// </summary>
public const string Update = "update";

/// <summary>
/// If a document with the specified _key value exists
/// already, return a unique constraint violation error
/// so that the insert operation fails. This is also
/// the default behavior in case the overwrite mode is
/// not set, and the <see cref="PostDocumentsQuery.Overwrite"/>
/// flag is false or not set either.
/// </summary>
public const string Conflict = "conflict";
}
}
13 changes: 12 additions & 1 deletion arangodb-net-standard/DocumentApi/Models/PatchDocumentsQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;

namespace ArangoDBNetStandard.DocumentApi.Models
{
Expand Down Expand Up @@ -57,6 +58,12 @@ public class PatchDocumentsQuery
/// </summary>
public bool? Silent { get; set; }

/// <summary>
/// Whether to update an existing entry in the in-memory edge
/// cache if an edge document is updated.
/// </summary>
public bool? RefillIndexCaches { get; set; }

internal string ToQueryString()
{
var queryParams = new List<string>();
Expand Down Expand Up @@ -88,6 +95,10 @@ internal string ToQueryString()
{
queryParams.Add("silent=" + Silent.ToString().ToLower());
}
if (RefillIndexCaches != null)
{
queryParams.Add("refillIndexCaches=" + RefillIndexCaches.ToString().ToLower());
}
return string.Join("&", queryParams);
}
}
Expand Down
58 changes: 57 additions & 1 deletion arangodb-net-standard/DocumentApi/Models/PostDocumentsQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace ArangoDBNetStandard.DocumentApi.Models
/// </summary>
public class PostDocumentsQuery
{
/// <summary>
/// Wait until document has been synced to disk.
/// </summary>
public bool? WaitForSync { get; set; }

/// <summary>
Expand All @@ -28,10 +31,47 @@ public class PostDocumentsQuery
public bool? Silent { get; set; }

/// <summary>
/// If a document already exists, whether to overwrite (replace) the document rather than respond with error.
/// If a document already exists, whether to overwrite (replace)
/// the document rather than respond with error.
/// </summary>
public bool? Overwrite { get; set; }

/// <summary>
/// This option supersedes <see cref="Overwrite"/> and offers
/// the several modes listed in <see cref="OverwriteModes"/>.
/// </summary>
public string OverwriteMode { get; set; }

/// <summary>
/// If the intention is to delete existing attributes
/// with the update-insert command, the URL query
/// parameter keepNull can be used with a value of
/// false. This modifies the behavior of the patch
/// command to remove any attributes from the
/// existing document that are contained in the patch
/// document with an attribute value of null.
/// This option controls the update-insert behavior only.
/// </summary>
public bool? KeepNull { get; set; }

/// <summary>
/// Controls whether objects (not arrays) are
/// merged if present in both, the existing and
/// the update-insert document. If set to false,
/// the value in the patch document overwrites
/// the existing document’s value. If set to true,
/// objects are merged. The default is true.
/// This option controls the update-insert
/// behavior only.
/// </summary>
public bool? MergeObjects { get; set; }

/// <summary>
/// Whether to add a new entry to the in-memory
/// edge cache if an edge document is inserted.
/// </summary>
public bool? RefillIndexCaches { get; set; }

/// <summary>
/// Get the set of options in a format suited to a URL query string.
/// </summary>
Expand Down Expand Up @@ -59,6 +99,22 @@ internal string ToQueryString()
{
query.Add("overwrite=" + Overwrite.ToString().ToLower());
}
if (OverwriteMode != null)
{
query.Add("overwriteMode =" + OverwriteMode.ToLower());
}
if (KeepNull != null)
{
query.Add("keepNull=" + KeepNull.ToString().ToLower());
}
if (MergeObjects != null)
{
query.Add("mergeObjects=" + MergeObjects.ToString().ToLower());
}
if (RefillIndexCaches != null)
{
query.Add("refillIndexCaches=" + RefillIndexCaches.ToString().ToLower());
}
return string.Join("&", query);
}
}
Expand Down
10 changes: 10 additions & 0 deletions arangodb-net-standard/DocumentApi/Models/PutDocumentQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class PutDocumentQuery
/// </summary>
public bool? Silent { get; set; }

/// <summary>
/// Whether to update an existing entry in the in-memory
/// edge cache if an edge document is replaced.
/// </summary>
public bool? RefillIndexCaches { get; set; }

/// <summary>
/// Get the set of options in a format suited to a URL query string.
/// </summary>
Expand Down Expand Up @@ -69,6 +75,10 @@ internal string ToQueryString()
{
query.Add("silent=" + Silent.ToString().ToLower());
}
if (RefillIndexCaches != null)
{
query.Add("refillIndexCaches=" + RefillIndexCaches.ToString().ToLower());
}
return string.Join("&", query);
}
}
Expand Down