Exemplo n.º 1
0
 private void AddGSIProjections(DynamoGSIProjections gsiProjections, CreateTableRequest createTableRequest)
 {
     if (gsiProjections != null)
     {
         foreach (var globalSecondaryIndex in createTableRequest.GlobalSecondaryIndexes)
         {
             if (gsiProjections.Projections.TryGetValue(globalSecondaryIndex.IndexName,
                                                        out Projection projection))
             {
                 globalSecondaryIndex.Projection = projection;
             }
             else
             {
                 globalSecondaryIndex.Projection = new Projection {
                     ProjectionType = ProjectionType.ALL
                 };
             }
         }
     }
     else
     {
         foreach (var globalSecondaryIndex in createTableRequest.GlobalSecondaryIndexes)
         {
             globalSecondaryIndex.Projection = new Projection {
                 ProjectionType = ProjectionType.ALL
             };
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Builds a CreateTableRequest object from an entity type marked up with the object model; other parameters
        /// set table properties from that. Only supports string, number and byte array properties, others should
        /// be unmarked. Generally, don't create a DBProperty unless you need to use in a Filter, and rely on
        /// DynamoDb client library to figure out how to store.
        /// We will default both throughput on tables and GSI to on demand if you don't provide them
        /// We will default projections to all, if you don't provide them
        /// </summary>
        /// <param name="provisonedThroughput">What is the provisioned throughput for the table. Defaults to 10 read and write units</param>
        /// <param name="gsiProjections">How are global secondary indexes projected; defaults to all</param>
        /// <param name="billingMode">What billing mode (provisioned or request)</param>
        /// <param name="sseSpecification"></param>
        /// <param name="streamSpecification"></param>
        /// <param name="tags"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public CreateTableRequest GenerateCreateTableMapper <T>(
            DynamoDbCreateProvisionedThroughput provisonedThroughput,
            DynamoGSIProjections gsiProjections     = null,
            BillingMode billingMode                 = null,
            SSESpecification sseSpecification       = null,
            StreamSpecification streamSpecification = null,
            IEnumerable <Tag> tags = null)
        {
            var    docType   = typeof(T);
            string tableName = GetTableName <T>(docType);

            var createTableRequest = new CreateTableRequest(tableName, GetPrimaryKey <T>(docType).ToList());

            AddTableProvisionedThrougput <T>(provisonedThroughput, createTableRequest);
            createTableRequest.AttributeDefinitions.AddRange(GetAttributeDefinitions <T>(docType));
            createTableRequest.GlobalSecondaryIndexes.AddRange(GetGlobalSecondaryIndices <T>(docType).Select(entry => entry.Value));
            AddGSIProvisionedThroughput <T>(provisonedThroughput, createTableRequest);
            AddGSIProjections(gsiProjections, createTableRequest);
            createTableRequest.LocalSecondaryIndexes.AddRange(GetLocalSecondaryIndices <T>(docType));
            createTableRequest.BillingMode      = billingMode ?? BillingMode.PROVISIONED;
            createTableRequest.SSESpecification = sseSpecification ?? new SSESpecification {
                Enabled = true
            };
            createTableRequest.StreamSpecification = streamSpecification ?? new StreamSpecification {
                StreamEnabled = true, StreamViewType = StreamViewType.NEW_IMAGE
            };
            createTableRequest.Tags = tags != null?tags.ToList() : new List <Tag>
            {
                new Tag {
                    Key = "outbox", Value = "brighter_outbox"
                }
            };
            return(createTableRequest);
        }