Exemplo n.º 1
0
        //--- Methods ---
        private void PrepareRequest(bool fetchAllAttributes)
        {
            // inherit the expected types from the query select construct
            foreach (var expectedType in _queryClause.TypeFilters)
            {
                _converter.AddExpectedType(expectedType);
            }

            // initialize request
            _request.IndexName = _queryClause.IndexName;
            _request.KeyConditionExpression = _queryClause.GetKeyConditionExpression(_converter);
            _request.FilterExpression       = _converter.ConvertConditions(_table.Options);
            _request.ProjectionExpression   = _converter.ConvertProjections();

            // NOTE (2021-06-23, bjorg): the following logic matches the default behavior, but makes it explicit
            // if `ProjectionExpression` is set, only return specified attributes; otherwise, for an index, return projected attributes only; for tables, return all attributes from each row
            if (_request.ProjectionExpression is null)
            {
                if ((_request.IndexName is null) || fetchAllAttributes)
                {
                    _request.Select = Select.ALL_ATTRIBUTES;
                }
                else
                {
                    _request.Select = Select.ALL_PROJECTED_ATTRIBUTES;
                }
            }
        //--- Methods ---
        public IDynamoTableTransactGetItemsBegin <TRecord> BeginGetItem <TRecord>(DynamoPrimaryKey <TRecord> primaryKey, bool consistentRead = false) where TRecord : class
        {
            // transaction GetItem
            var transactGetItem = new TransactGetItem {
                Get = new Get {
                    TableName = _table.TableName,
                    Key       = new Dictionary <string, AttributeValue> {
                        [primaryKey.PKName] = new AttributeValue(primaryKey.PKValue),
                        [primaryKey.SKName] = new AttributeValue(primaryKey.SKValue)
                    }
                }
            };

            _request.TransactItems.Add(transactGetItem);

            // add expressions converter
            var converter = new DynamoRequestConverter(transactGetItem.Get.ExpressionAttributeNames, _table.SerializerOptions);

            _converters.Add(converter);

            // register expected type
            converter.AddExpectedType(typeof(TRecord));
            return(new DynamoTableTransactGetItemsEntry <TRecord>(this, converter));
        }