示例#1
0
        public DynamoQuery Filter(params Expression[] conditions)
        {
            if (_filter == null)
            {
                if (ExpressionAttributeNames == null)
                {
                    ExpressionAttributeNames = new JsonObject();
                }
                if (ExpressionAttributeValues == null)
                {
                    ExpressionAttributeValues = new AttributeCollection();
                }

                _filter = new DynamoExpression(ExpressionAttributeNames, ExpressionAttributeValues);
            }

            foreach (var condition in conditions)
            {
                _filter.Add(condition);
            }

            this.FilterExpression = _filter.Text;

            return(this);
        }
示例#2
0
        public static DynamoExpression Conjunction(params Expression[] expressions)
        {
            var result = new DynamoExpression();

            result.AddRange(expressions);

            return(result);
        }
示例#3
0
        public static DynamoExpression FromExpression(Expression expression)
        {
            var result = new DynamoExpression();

            result.Add(expression);

            return(result);
        }
示例#4
0
        public ScanRequest(string tableName, Expression[] conditions)
        {
            TableName = tableName ?? throw new ArgumentNullException(nameof(tableName));

            if (conditions != null)
            {
                SetFilterExpression(DynamoExpression.Conjunction(conditions));
            }
        }
示例#5
0
        public ScanRequest(string tableName, Expression[] conditions)
        {
            TableName = tableName;

            if (conditions != null)
            {
                SetFilterExpression(DynamoExpression.Conjunction(conditions));
            }
        }
示例#6
0
        private void AddFilterExpression(Expression expression)
        {
            if (FilterExpression == null)
            {
                FilterExpression = new DynamoExpression(AttributeNames, AttributeValues);
            }

            FilterExpression.Add(expression);
        }
示例#7
0
        public static DynamoExpression FromExpression(Expression expression)
        {
            var result = new DynamoExpression();

            // TODO: Flatten conjunctions...

            result.Add(expression);

            return(result);
        }
示例#8
0
        internal void SetFilterExpression(DynamoExpression expression)
        {
            FilterExpression = expression.Text;

            if (expression.HasAttributeNames)
            {
                ExpressionAttributeNames = expression.AttributeNames;
            }

            if (expression.HasAttributeValues)
            {
                ExpressionAttributeValues = expression.AttributeValues;
            }
        }
示例#9
0
        internal void SetConditions(Expression[] conditions)
        {
            var expression = DynamoExpression.Conjunction(conditions);

            ConditionExpression = expression.Text;

            if (expression.HasAttributeNames)
            {
                ExpressionAttributeNames = expression.AttributeNames;
            }

            if (expression.HasAttributeValues)
            {
                ExpressionAttributeValues = expression.AttributeValues;
            }
        }
示例#10
0
        // TODO: Expand BinaryExpression

        public DynamoQueryExpression(string[] keyNames, Expression[] expressions)
        {
            this.keyNames = keyNames;

            KeyExpression = new DynamoExpression(AttributeNames, AttributeValues);

            foreach (Expression expression in expressions)
            {
                if (expression is BinaryExpression be)
                {
                    if (IsKey(be.Left.ToString() !))
                    {
                        KeyExpression.Add(be);
                    }
                    else
                    {
                        AddFilterExpression(be);
                    }
                }
示例#11
0
        public DynamoQuery(params Expression[] keyConditions)
        {
            if (keyConditions.Length == 0)
            {
                return;
            }

            var x = DynamoExpression.Conjunction(keyConditions);

            if (x.HasAttributeNames)
            {
                ExpressionAttributeNames = x.AttributeNames;
            }

            if (x.HasAttributeValues)
            {
                ExpressionAttributeValues = x.AttributeValues;
            }

            KeyConditionExpression = x.Text;
        }
示例#12
0
        public UpdateItemRequest(
            string tableName,
            IEnumerable <KeyValuePair <string, object> > key,
            Change[] changes,
            Expression[]?conditions   = null,
            ReturnValues?returnValues = null)
        {
            TableName    = tableName ?? throw new ArgumentNullException(nameof(tableName));
            Key          = key ?? throw new ArgumentNullException(nameof(key));
            Changes      = changes ?? throw new ArgumentNullException(nameof(changes));
            ReturnValues = returnValues;

            if (conditions != null && conditions.Length > 0)
            {
                var expression = new DynamoExpression(ExpressionAttributeNames, ExpressionAttributeValues);

                expression.AddRange(conditions);

                ConditionExpression = expression.Text;
            }
        }
示例#13
0
        public DynamoQueryExpression(string[] keyNames, Expression[] expressions)
        {
            this.keyNames = keyNames;

            KeyExpression = new DynamoExpression(AttributeNames, AttributeValues);

            foreach (var expression in expressions)
            {
                if (expression is BinaryExpression)
                {
                    var e = (BinaryExpression)expression;

                    if (IsKey(e.Left.ToString()))
                    {
                        KeyExpression.Add(e);
                    }
                    else
                    {
                        AddFilterExpression(e);
                    }
                }
                else if (expression is BetweenExpression)
                {
                    var e = (BetweenExpression)expression;

                    if (IsKey(e.Property.ToString()))
                    {
                        KeyExpression.Add(e);
                    }
                    else
                    {
                        AddFilterExpression(e);
                    }
                }
                else
                {
                    throw new Exception("Unexpected expression type:" + expression);
                }
            }
        }
示例#14
0
        public IEnumerable <T> Enumerate(params Expression[] conditions) // Scans the entire table
        {
            // Each scan may return upto 1MB of data
            // TODO, consider parellel scans

            DynamoExpression filterExpression = null;

            if (conditions.Length > 0)
            {
                filterExpression = DynamoExpression.Conjunction(conditions);
            }

            var result = new QueryResult();

            do
            {
                var request = new ScanRequest(tableName)
                {
                    Limit             = 1000,
                    ExclusiveStartKey = result.LastEvaluatedKey
                };

                if (filterExpression != null)
                {
                    request.SetFilterExpression(filterExpression);
                }

                result = client.Scan(request).Result;

                // If LastEvaluatedKey is null, then the "last page" of results has been processed and there is no more data to be retrieved.
                // If LastEvaluatedKey is anything other than null, this does not necessarily mean that there is more data in the result set.
                // The only way to know when you have reached the end of the result set is when LastEvaluatedKey is null.

                foreach (var item in result.Items)
                {
                    yield return(item.As <T>(metadata));
                }
            }while (result.LastEvaluatedKey != null);
        }
示例#15
0
        public async Task <IList <T> > ScanAsync(IEnumerable <KeyValuePair <string, object> > startKey = null,
                                                 Expression[] conditions = null,
                                                 int take = 1000)
        {
            var request = new ScanRequest(tableName)
            {
                Limit = take
            };

            if (conditions != null && conditions.Length > 0)
            {
                request.SetFilterExpression(DynamoExpression.Conjunction(conditions));
            }

            if (startKey != null)
            {
                request.ExclusiveStartKey = AttributeCollection.FromJson(startKey.ToJson());
            }

            var result = await client.Scan(request).ConfigureAwait(false);

            return(new QueryResult <T>(result));
        }