Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Commit

Permalink
Adds RemoveByIdAsync with object based partition key value overload
Browse files Browse the repository at this point in the history
  • Loading branch information
Elfocrash committed Dec 15, 2018
1 parent 45f7992 commit ff4a79b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Cosmonaut/CosmosStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ public async Task<CosmosResponse<TEntity>> RemoveByIdAsync(string id, RequestOpt
return new CosmosResponse<TEntity>(response);
}

public async Task<CosmosResponse<TEntity>> RemoveByIdAsync(string id, object partitionKeyValue, CancellationToken cancellationToken = default)
{
var requestOptions = partitionKeyValue != null
? new RequestOptions { PartitionKey = new PartitionKey(partitionKeyValue) }
: null;

return await RemoveByIdAsync(id, requestOptions, cancellationToken);
}

public async Task<TEntity> FindAsync(string id, RequestOptions requestOptions = null, CancellationToken cancellationToken = default)
{
return await CosmonautClient.GetDocumentAsync<TEntity>(DatabaseName, CollectionName, id,
Expand Down
16 changes: 15 additions & 1 deletion src/Cosmonaut/ICosmosStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public interface ICosmosStore<TEntity> where TEntity : class
Task<CosmosMultipleResponse<TEntity>> RemoveRangeAsync(IEnumerable<TEntity> entities, Func<TEntity, RequestOptions> requestOptions = null, CancellationToken cancellationToken = default);

/// <summary>
/// Removes the entity with he specified Id from the cosmos db store.
/// Removes the entity with the specified Id from the cosmos db store.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="id">The id of the entity attempting to remove. </param>
Expand All @@ -277,6 +277,20 @@ public interface ICosmosStore<TEntity> where TEntity : class
/// </returns>
Task<CosmosResponse<TEntity>> RemoveByIdAsync(string id, RequestOptions requestOptions = null, CancellationToken cancellationToken = default);

/// <summary>
/// Removes the entity with the specified Id from the cosmos db store.
/// </summary>
/// <typeparam name="TEntity">The type of the entity.</typeparam>
/// <param name="id">The id of the entity attempting to remove. </param>
/// <param name="partitionKeyValue">The partition key value.</param>
/// <param name="cancellationToken">The CancellationToken for this operation.</param>
/// <returns>
/// A task that represents the asynchronous RemoveById operation. The task result contains the
/// <see cref="CosmosResponse{TEntity}"/> for the entity. The response provides access to
/// various response information such as whether it was successful or what (if anything) went wrong.
/// </returns>
Task<CosmosResponse<TEntity>> RemoveByIdAsync(string id, object partitionKeyValue, CancellationToken cancellationToken = default);

/// <summary>
/// Returns an entity by document/entity id from the cosmos db store. If the collection is partitioned you will need to provide the
/// partition key value in the <see cref="RequestOptions"/>.
Expand Down

0 comments on commit ff4a79b

Please sign in to comment.