Skip to content

Commit

Permalink
feat: add the possibility of ConsistentRead for queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Cussa committed Oct 19, 2023
1 parent 0970e22 commit 15acb3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/DynaMight/Builders/IQueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public interface IQueryBuilder : IDynamoBuilder
/// <returns>The QueryBuilder (for a fluent API usage)</returns>
IQueryBuilder OrderByDescending();
/// <summary>
/// Sets the Query to use Strongly Consistent Reads.
/// </summary>
/// <remarks>Check https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html for more information</remarks>
/// <returns>The QueryBuilder (for a fluent API usage)</returns>
IQueryBuilder ConsistentRead();
/// <summary>
/// Sets the Index name, in case you are using a different index for the query
/// </summary>
/// <param name="indexName">The index name to be used</param>
Expand Down
11 changes: 10 additions & 1 deletion src/DynaMight/Builders/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class QueryBuilder : DynamoBuilder, IQueryBuilder
private string? _pageToken;
private bool _sortDescending;
private string? _indexName;
private bool _consistentRead;

/// <summary>
/// Creates a new Query Builder
Expand Down Expand Up @@ -78,6 +79,13 @@ public IQueryBuilder OrderByDescending()
_sortDescending = true;
return this;
}

/// <inheritdoc />
public IQueryBuilder ConsistentRead()
{
_consistentRead = true;
return this;
}

/// <inheritdoc />
public IQueryBuilder SetIndexName(string? indexName)
Expand Down Expand Up @@ -113,6 +121,7 @@ public QueryOperationConfig Build(bool useFilter)
Limit = _pageSize,
PaginationToken = _pageToken,
BackwardSearch = _sortDescending,
FilterExpression = useFilter ? BuildExpression() : null
FilterExpression = useFilter ? BuildExpression() : null,
ConsistentRead = _consistentRead
};
}

0 comments on commit 15acb3d

Please sign in to comment.