/// <summary> /// Create a new <paramref name="table"/> on your AWS account as an asynchronous operation. /// </summary> /// <param name="table">The name of the table to create.</param> /// <param name="index">The attributes that make up the primary key for a table or an index.</param> /// <param name="setup">The <see cref="TableOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <CreateTableResponse> CreateAsync(string table, PrimaryIndex index, Action <TableOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); Validator.ThrowIfNull(index, nameof(index)); var options = setup.ConfigureOptions(); var ctr = new CreateTableRequest() { TableName = table, AttributeDefinitions = index.ToAttributeDefinitions().Concat(options.GlobalSecondaryIndexes.SelectMany(gsi => gsi.ToAttributeDefinitions())).ToList(), GlobalSecondaryIndexes = options.GlobalSecondaryIndexes.Select(ti => new GlobalSecondaryIndex { IndexName = ti.IndexName, KeySchema = ti.ToKeySchema(), ProvisionedThroughput = ti.Throughput, Projection = ti.Projection.ToProjection() }).ToList(), KeySchema = index.ToKeySchema(), LocalSecondaryIndexes = index.LocalSecondaryIndexes.Select(ti => new LocalSecondaryIndex { IndexName = ti.IndexName, KeySchema = ti.ToKeySchema(), Projection = ti.Projection.ToProjection() }).ToList(), ProvisionedThroughput = options.Throughput, StreamSpecification = options.StreamSpecification }; return(Client.CreateTableAsync(ctr, options.CancellationToken)); }
/// <summary> /// Returns one or more items and item attributes by accessing every item in a <paramref name="table"/> or a secondary index as an asynchronous operation. /// </summary> /// <param name="table">The name of the table containing the requested items.</param> /// <param name="setup">The <see cref="ScanOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <ScanResponse> ScanAsync(string table, Action <ScanOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); var options = setup.ConfigureOptions(); var sr = new ScanRequest() { TableName = table, ReturnConsumedCapacity = options.ResponseCapacity.ToReturnConsumedCapacity(), ExpressionAttributeNames = options.ExpressionMapping, ExpressionAttributeValues = options.Expression.ToAttributeValues(), Select = options.SelectAttributes.ToSelect(), ProjectionExpression = options.ProjectionExpression, ConsistentRead = options.ConsistentRead, ExclusiveStartKey = options.ExclusiveStartKey?.ToAttributeValues(), FilterExpression = options.FilterExpression, IndexName = options.IndexName }; if (options.Limit.HasValue) { sr.Limit = options.Limit.Value; } if (options.Segment.HasValue) { sr.Segment = options.Segment.Value; } if (options.TotalSegments.HasValue) { sr.TotalSegments = options.TotalSegments.Value; } return(Client.ScanAsync(sr, options.CancellationToken)); }
/// <summary> /// Finds items based on primary key values as an asynchronous operation. /// </summary> /// <param name="table">The name of the table containing the requested items.</param> /// <param name="keyConditionExpression">The condition that specifies the partition key value(s) for items to be retrieved.</param> /// <param name="expression">The values that can be substituted in an expression.</param> /// <param name="setup">The <see cref="QueryOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <QueryResponse> QueryAsync(string table, string keyConditionExpression, Expression expression, Action <QueryOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); Validator.ThrowIfNullOrWhitespace(keyConditionExpression, nameof(keyConditionExpression)); Validator.ThrowIfNull(expression, nameof(expression)); var options = setup.ConfigureOptions(); var qr = new QueryRequest() { TableName = table, ReturnConsumedCapacity = options.ResponseCapacity.ToReturnConsumedCapacity(), ExpressionAttributeNames = options.ExpressionMapping, ExpressionAttributeValues = expression.ToAttributeValues(), Select = options.SelectAttributes.ToSelect(), ProjectionExpression = options.ProjectionExpression, ConsistentRead = options.ConsistentRead, ExclusiveStartKey = options.ExclusiveStartKey?.ToAttributeValues(), FilterExpression = options.FilterExpression, IndexName = options.IndexName, KeyConditionExpression = keyConditionExpression, ScanIndexForward = options.ScanIndexForward }; if (options.Limit.HasValue) { qr.Limit = options.Limit.Value; } return(Client.QueryAsync(qr, options.CancellationToken)); }
/// <summary> /// Returns information about the <paramref name="table"/>, including the current status of the <paramref name="table"/>, when it was created, the primary key schema, and any indexes on the <paramref name="table"/> as an asynchronous operation. /// </summary> /// <param name="table">The name of the table to describe.</param> /// <param name="setup">The <see cref="AsyncOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <DescribeTableResponse> DescribeAsync(string table, Action <AsyncOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); var options = setup.ConfigureOptions(); var dtr = new DescribeTableRequest() { TableName = table }; return(Client.DescribeTableAsync(dtr, options.CancellationToken)); }
/// <summary> /// Update the TTL for the specified <paramref name="table"/> as an asynchronous operation. /// </summary> /// <param name="table">The name of the table to be configured.</param> /// <param name="setup">The <see cref="TimeToLiveOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <UpdateTimeToLiveResponse> UpdateTimeToLiveAsync(string table, Action <TimeToLiveOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); var options = setup.ConfigureOptions(); var uttlr = new UpdateTimeToLiveRequest() { TableName = table, TimeToLiveSpecification = options.Specification }; return(Client.UpdateTimeToLiveAsync(uttlr, options.CancellationToken)); }
/// <summary> /// Modifies the provisioned throughput settings, global secondary indexes, or DynamoDB Streams settings for a given <paramref name="table"/> as an asynchronous operation. /// </summary> /// <param name="table">The name of the table to be updated.</param> /// <param name="setup">The <see cref="UpdateTableOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <UpdateTableResponse> UpdateAsync(string table, Action <UpdateTableOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); var options = setup.ConfigureOptions(); var utr = new UpdateTableRequest() { TableName = table, ProvisionedThroughput = options.Throughput, AttributeDefinitions = options.GlobalSecondaryIndexes.SelectMany(gsi => gsi.ToAttributeDefinitions()).ToList(), StreamSpecification = options.StreamSpecification, GlobalSecondaryIndexUpdates = options.ToGlobalSecondaryIndexUpdates() }; return(Client.UpdateTableAsync(utr, options.CancellationToken)); }
/// <summary> /// Returns a set of attributes for the item with the given primary <paramref name="key"/> as an asynchronous operation. /// </summary> /// <param name="table">The name of the table containing the requested item.</param> /// <param name="key">The map of attribute names to <see cref="AttributeValue"/> objects, representing the primary key of the item to retrieve.</param> /// <param name="setup">The <see cref="ResponseOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <GetItemResponse> GetAsync(string table, PrimaryKey key, Action <ResponseOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); Validator.ThrowIfNull(key, nameof(key)); var options = setup.ConfigureOptions(); var gir = new GetItemRequest() { TableName = table, ReturnConsumedCapacity = options.ResponseCapacity.ToReturnConsumedCapacity(), ExpressionAttributeNames = options.ExpressionMapping, Key = key.ToAttributeValues(), ConsistentRead = options.ConsistentRead, ProjectionExpression = options.ProjectionExpression }; return(Client.GetItemAsync(gir, options.CancellationToken)); }
/// <summary> /// Deletes a single item in a <paramref name="table"/> by primary <paramref name="key"/> as an asynchronous operation. /// </summary> /// <param name="table">The name of the table from which to delete the item.</param> /// <param name="key">The map of attribute names to <see cref="AttributeValue"/> objects, representing the primary key of the item to delete.</param> /// <param name="setup">The <see cref="ItemOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <DeleteItemResponse> DeleteAsync(string table, PrimaryKey key, Action <ItemOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); Validator.ThrowIfNull(key, nameof(key)); var options = setup.ConfigureOptions(); var dir = new DeleteItemRequest() { TableName = table, ReturnValues = options.ResponseAttributes.ToReturnValue(TableItemOperation.Delete), ReturnItemCollectionMetrics = options.ResponseMetrics.ToReturnItemCollectionMetrics(), ConditionExpression = options.ConditionExpression, ReturnConsumedCapacity = options.ResponseCapacity.ToReturnConsumedCapacity(), ExpressionAttributeValues = options.Expression.ToAttributeValues(), ExpressionAttributeNames = options.ExpressionMapping, Key = key.ToAttributeValues() }; return(Client.DeleteItemAsync(dir, options.CancellationToken)); }
/// <summary> /// Creates a new <paramref name="item"/>, or replaces an old item with a new <paramref name="item"/> as an asynchronous operation. /// </summary> /// <param name="table">The name of the table to contain the item.</param> /// <param name="item">The map of attribute name/value pairs, one for each attribute.</param> /// <param name="setup">The <see cref="ItemOptions" /> which need to be configured.</param> /// <returns>The task object representing the asynchronous operation.</returns> public Task <PutItemResponse> PutAsync(string table, TableItem item, Action <ItemOptions> setup = null) { DynamoValidator.ThrowIfTableNameIsNotValid(table); Validator.ThrowIfNull(item, nameof(item)); var options = setup.ConfigureOptions(); var pir = new PutItemRequest() { TableName = table, Item = item.Attributes, ConditionExpression = options.ConditionExpression, ExpressionAttributeNames = options.ExpressionMapping, ExpressionAttributeValues = options.Expression.ToAttributeValues(), ReturnConsumedCapacity = options.ResponseCapacity.ToReturnConsumedCapacity(), ReturnItemCollectionMetrics = options.ResponseMetrics.ToReturnItemCollectionMetrics(), ReturnValues = options.ResponseAttributes.ToReturnValue(TableItemOperation.Create) }; return(Client.PutItemAsync(pir, options.CancellationToken)); }