예제 #1
0
        /// <summary>
        /// Gets a resource of a given type and with the provided id from a given table
        /// </summary>
        /// <param name="table"></param>
        /// <param name="typeName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private async Task <dynamic> Get(DynamoDbTable table, string typeName, string id)
        {
            var hashKey  = new Primitive($"{typeName}");
            var rangeKey = new Primitive(id);

            Logger.Debug("Getting item with hash key {0} and range key {1} from table {2}...", hashKey, rangeKey, table.TableName);

            var result = await table.GetItemAsync(hashKey, rangeKey);

            return(result != null?DynamoDbDocumentHelper.ToObject(result) : null);
        }
예제 #2
0
        /// <summary>
        /// Creates or updates record in DynamoDB
        /// </summary>
        /// <param name="resource"></param>
        /// <returns></returns>
        private async Task <dynamic> CreateOrUpdate(dynamic resource)
        {
            await(await Table(resource.Type)).PutItemAsync(DynamoDbDocumentHelper.ToDocument(resource));

            return(await Get(resource.Type, resource.Id));
        }
예제 #3
0
        /// <summary>
        /// Creates or updates record in DynamoDB
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resource"></param>
        /// <returns></returns>
        private async Task <T> CreateOrUpdate <T>(dynamic resource) where T : Resource, new()
        {
            await(await Table(typeof(T))).PutItemAsync(DynamoDbDocumentHelper.ToDocument(resource));

            return(await Get <T>(resource.Id));
        }
예제 #4
0
 /// <summary>
 /// Queries resources of type <see cref="T"/> using the provided criteria, in the form of key/value pairs
 /// </summary>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public async Task <IEnumerable <dynamic> > Query <T>(IDictionary <string, string> parameters) where T : Resource, new()
 {
     return
         ((await(await Table(typeof(T))).Query(new Primitive(typeof(T).Name), parameters.ToQueryFilter()).GetRemainingAsync())
          .Select(d => DynamoDbDocumentHelper.ToObject(d)));
 }