Пример #1
0
        /// <summary>
        /// Add a filter for the given field path.
        /// </summary>
        /// <remarks>
        /// This call adds additional filters to any previously-specified ones.
        /// </remarks>
        /// <param name="fieldPath">The field path to filter on. Must not be null.</param>
        /// <param name="op">The filter operator.</param>
        /// <param name="value">The value to compare in the filter.</param>
        /// <returns>A new query based on the current one, but with the additional specified filter applied.</returns>
        public Query Where(FieldPath fieldPath, QueryOperator op, object value)
        {
            FieldOp queryOp       = GetOperator(op);
            var     unaryOperator = GetUnaryOperator(value);
            Filter  filter;

            if (unaryOperator != UnaryFilter.Types.Operator.Unspecified)
            {
                if (queryOp == FieldOp.Equal)
                {
                    filter = new Filter {
                        UnaryFilter = new UnaryFilter {
                            Field = fieldPath.ToFieldReference(), Op = unaryOperator
                        }
                    };
                }
                else
                {
                    throw new ArgumentException(nameof(value), "null and NaN values can only be used with the Equal operator");
                }
            }
            else
            {
                var convertedValue = ValueSerializer.Serialize(value);
                filter = new Filter {
                    FieldFilter = new FieldFilter {
                        Field = fieldPath.ToFieldReference(), Op = queryOp, Value = convertedValue
                    }
                };
            }
            return(WithFilter(filter));
        }
Пример #2
0
        private Query OrderBy(FieldPath fieldPath, Direction direction)
        {
            GaxPreconditions.CheckState(QueryProto.StartAt == null && QueryProto.EndAt == null,
                                        "All orderings must be specified before StartAt, StartAfter, EndBefore or EndAt are called.");
            var query = QueryProto.Clone();

            query.OrderBy.Add(new Order {
                Field = fieldPath.ToFieldReference(), Direction = direction
            });
            return(WithQuery(query));
        }