public async Task <StoryContent> FindByQuery(IQueryParameter query, CancellationToken cancellationToken)
        {
            var storyId   = ((StoryQuery)query).StoryId;
            var dbContext = _clientFactory.GetDynamoDBContext();

            return(await dbContext.LoadAsync <StoryContent>(storyId, _dynamoDBOperationConfig, cancellationToken));
        }
Example #2
0
        public async Task <TEntity> FindByQuery(IQueryParameter query, CancellationToken cancellationToken)
        {
            var personQuery   = (PersonIdentifier)query;
            var dynamoContext = _clientFactory.GetDynamoDBContext();


            var dynamoOperationContext = new DynamoDBOperationConfig()
            {
                ConditionalOperator = ConditionalOperatorValues.And,
                TableNamePrefix     = "familybryce."
            };


            if (personQuery.PersonId.HasValue)
            {
                return(await dynamoContext.LoadAsync <TEntity>(personQuery.PersonId.Value, _dynamoDBOperationConfig, cancellationToken));
            }
            else
            {
                dynamoOperationContext.QueryFilter.Add(new ScanCondition("FirstName", ScanOperator.Equal, personQuery.FirstName));
                dynamoOperationContext.QueryFilter.Add(new ScanCondition("LastName", ScanOperator.Equal, personQuery.LastName));
                dynamoOperationContext.QueryFilter.Add(new ScanCondition("EmailAddress", ScanOperator.Equal, personQuery.EmailAddress));
                var person = await dynamoContext.QueryAsync <TEntity>(dynamoOperationContext).GetRemainingAsync();

                return(person.FirstOrDefault());
            }
        }
        public void AddValueParameters(IQueryParameter input)
        {
            var inputProperties = input.GetType().GetProperties().ToArray();

            if (Parameters == null)
            {
                Parameters = new Dictionary <string, object>();
            }

            foreach (var propertyInfo in _propertyInfos)
            {
                var inputPro = inputProperties.FirstOrDefault(i => string.Equals(i.Name, propertyInfo.Name, StringComparison.CurrentCultureIgnoreCase));

                if (inputPro == null)
                {
                    continue;
                }

                var value = inputPro.GetValue(input, null);

                var name = propertyInfo.Name.ToLower();

                Parameters.Add(name, value);
            }
        }
        public async void QueryParameters()
        {
            string url = $"{_baseUrl}/items?elements.personas%5Ball%5D=barista%2Ccoffee%2Cblogger&elements.personas%5Bany%5D=barista%2Ccoffee%2Cblogger&system.sitemap_locations%5Bcontains%5D=cafes&elements.product_name=Hario%20V60&elements.price%5Bgt%5D=1000&elements.price%5Bgte%5D=50&system.type%5Bin%5D=cafe%2Ccoffee&elements.price%5Blt%5D=10&elements.price%5Blte%5D=4&elements.country%5Brange%5D=Guatemala%2CNicaragua&depth=2&elements=price%2Cproduct_name&limit=10&order=elements.price%5Bdesc%5D&skip=2&language=en";

            _mockHttp.When($"{url}")
            .Respond("application/json", " { 'items': [],'modular_content': {},'pagination': {'skip': 2,'limit': 10,'count': 0,'next_page': ''}}");

            var client = InitializeDeliverClientWithACustomeTypeProvider();

            var parameters = new IQueryParameter[]
            {
                new AllFilter("elements.personas", "barista", "coffee", "blogger"),
                new AnyFilter("elements.personas", "barista", "coffee", "blogger"),
                new ContainsFilter("system.sitemap_locations", "cafes"),
                new EqualsFilter("elements.product_name", "Hario V60"),
                new GreaterThanFilter("elements.price", "1000"),
                new GreaterThanOrEqualFilter("elements.price", "50"),
                new InFilter("system.type", "cafe", "coffee"),
                new LessThanFilter("elements.price", "10"),
                new LessThanOrEqualFilter("elements.price", "4"),
                new RangeFilter("elements.country", "Guatemala", "Nicaragua"),
                new DepthParameter(2),
                new ElementsParameter("price", "product_name"),
                new LimitParameter(10),
                new OrderParameter("elements.price", SortOrder.Descending),
                new SkipParameter(2),
                new LanguageParameter("en")
            };

            var response = await client.GetItemsAsync(parameters);

            Assert.Equal(0, response.Items.Count);
        }
Example #5
0
        /// <summary>
        /// Configure parameter to include in query
        /// </summary>
        /// <param name="parameter">Parameter to configure</param>
        /// <param name="value">Parameter to include in query</param>
        public static IQueryParameter <TDocument> Value <TDocument>(this IQueryParameter <TDocument> parameter, SearchQuery <TDocument> value)
            where TDocument : Document
        {
            parameter.Value = value;

            return(parameter);
        }
Example #6
0
        public async void QueryParameters()
        {
            var parameters = new IQueryParameter[]
            {
                new AllFilter("elements.personas", "barista", "coffee", "blogger"),
                new AnyFilter("elements.personas", "barista", "coffee", "blogger"),
                new ContainsFilter("system.sitemap_locations", "cafes"),
                new EqualsFilter("elements.product_name", "Hario V60"),
                new GreaterThanFilter("elements.price", "1000"),
                new GreaterThanOrEqualFilter("elements.price", "50"),
                new InFilter("system.type", "cafe", "coffee"),
                new LessThanFilter("elements.price", "10"),
                new LessThanOrEqualFilter("elements.price", "4"),
                new RangeFilter("elements.country", "Guatemala", "Nicaragua"),
                new DepthParameter(2),
                new ElementsParameter("price", "product_name"),
                new LimitParameter(10),
                new OrderParameter("elements.price", SortOrder.Descending),
                new SkipParameter(2),
                new LanguageParameter("en")
            };
            var response = await client.GetItemsAsync(parameters);

            Assert.Equal(0, response.Items.Count);
        }
Example #7
0
 public void AddParameter(IQueryParameter parameter)
 {
     _Command.Parameters.Add(
         InternalCreateParameter(parameter.Name, parameter.Value)
     );
     _Parameters.Add(parameter);
 }
Example #8
0
        public void Replace(string key, IQueryParameter parameter)
        {
            var keyValuePair = new KeyValuePair <string, IQueryParameter>(key, parameter);

            int index = this.Parameters.FindIndex(e => e.Key == key);

            this.Parameters[index] = keyValuePair;
        }
Example #9
0
 private void SetParameter(IQueryParameter parameter)
 {
     if (_parameters.ContainsKey(parameter.Name))
     {
         _parameters[parameter.Name] = parameter;
     }
     else
     {
         _parameters.Add(parameter.Name, parameter);
     }
 }
        public void Analyze(IQueryParameter input)
        {
            var columns =
                input.GetType().GetProperties()
                .Where(i => !SqlBuilderHelper.ShouldIgnore(i, IgnoreTypes));

            Columns = string.Join(
                ",\r\n",
                columns.Select(i => $@"{ParentTable}.[{i.Name}] = @{i.Name.ToLower()}")
                );
        }
Example #11
0
 public EsSearch(IElasticsearchContext context, IQueryParameter query)
 {
     context.CheckNull(nameof(context));
     query.CheckNull(nameof(query));
     _context       = context;
     _queryParam    = query;
     _sorts         = new List <ISort>();
     _includeFields = new List <Field>();
     _excludeFields = new List <Field>();
     _query         = new EsQuery <TResult>();
 }
Example #12
0
        public void Add(string key, IQueryParameter parameter)
        {
            if (!parameter.IsUnique && this.Parameters.Any(
                    e => e.Key == key &&
                    e.Value.GetType() == parameter.GetType()))
            {
                throw new QueryBuilderException(
                          $"Key-Parameter association have to be unique");
            }

            this.Parameters.Add(new KeyValuePair <string, IQueryParameter>(key, parameter));
        }
Example #13
0
        public static IEnumerable Select(IEnumerable items, IQueryParameter param, IListIndexes indexes = null)
        {
            IListIndex index = indexes?.GetIndex(param.Name);

            if (index == null)
            {
                return(index.Scan(param));
            }
            else
            {
                return(Search(items, param));
            }
        }
Example #14
0
        private static bool Concat(bool flag, bool rez, IQueryParameter parameter)
        {
            switch (parameter.Logic.Type)
            {
            case LogicTypes.Or:
                return(parameter.Logic.Not ? flag | !rez : flag | rez);

            case LogicTypes.And:
                return(parameter.Logic.Not ? flag & !rez : flag& rez);

            default:
                return(flag | rez);
            }
        }
Example #15
0
        public void ExecuteCommand(string sql, IQueryParameter parameter)
        {
            using (var command = GetCommand())
            {
                command.Connection  = _connection;
                command.CommandText = sql;
                foreach (var item in parameter.Get())
                {
                    command.Parameters.Add(GetParameter(item));
                }

                command.ExecuteNonQuery();
            }
        }
Example #16
0
        public DataSet ExecuteQuery(string sql, IQueryParameter parameter)
        {
            using (var command = GetCommand())
            {
                command.Connection  = _connection;
                command.CommandText = sql;
                foreach (var item in parameter.Get())
                {
                    command.Parameters.Add(GetParameter(item));
                }

                return(FillDataSet(command));
            }
        }
        public async Task <TEntity> FindByQuery(IQueryParameter query, CancellationToken cancellationToken)
        {
            var personQuery   = (UnionQuery)query;
            var dynamoContext = _clientFactory.GetDynamoDBContext();


            var dynamoOperationContext = new DynamoDBOperationConfig()
            {
                ConditionalOperator = ConditionalOperatorValues.And,
                TableNamePrefix     = "familybryce.",
                IndexName           = "Members-index",
            };

            var queryResult = await dynamoContext.QueryAsync <TEntity>(BuildIndex(personQuery.Partner1Id, personQuery.Partner2Id), dynamoOperationContext).GetRemainingAsync(cancellationToken);

            return(queryResult.FirstOrDefault());
        }
Example #18
0
        public void AddValueParameters(IQueryParameter input)
        {
            var inputProperties = input.GetType().GetProperties().ToArray();

            if (Parameters == null)
            {
                Parameters = new Dictionary <string, object>();
            }

            foreach (var propertyInfo in _propertyInfos)
            {
                var inputPro = inputProperties.FirstOrDefault(i => string.Equals(i.Name, propertyInfo.Name, StringComparison.CurrentCultureIgnoreCase));

                if (inputPro == null)
                {
                    continue;
                }

                var value = inputPro.GetValue(input, null);

                if (value == null)
                {
                    var toremove = _columns.FirstOrDefault(i => string.Equals(i.Name, inputPro.Name, StringComparison.CurrentCultureIgnoreCase));

                    if (toremove != null)
                    {
                        _columns.Remove(toremove);
                    }

                    continue;
                }

                var name = propertyInfo.Name.ToLower();

                Parameters.Add(name, value);
            }

            _values = string.Join(",", Parameters.Select(i => $"@{i.Key.ToLower()}"));
        }
Example #19
0
        public static IEnumerable Select(IEnumerable items, IQueryParameter param, IListIndexes indexes = null)
        {
            if (param.AlwaysTrue)
            {
                return(items);
            }

            if (param.Comparer.Type == CompareTypes.Distinct)
            {
                return(Distinct(items, param.Invoker));
            }

            IListIndex index = indexes?.GetIndex(param.Name);

            if (index == null)
            {
                return(index.Scan(param));
            }
            else
            {
                return(Search(items, param));
            }
        }
Example #20
0
		protected virtual IQueryParameter TransformParameter(IQueryParameter inParam, string paramName)
		{
			IQueryParameter outParam = null;
			if (inParam.DbType == DbType.Object)
			{
				IClassMap classMap = this.rootClassMap.DomainMap.MustGetClassMap(inParam.Value.GetType() );
				foreach (IPropertyMap propertyMap in classMap.GetIdentityPropertyMaps() )
				{
					object value = this.npathEngine.Context.ObjectManager.GetPropertyValue(inParam.Value, propertyMap.Name );
					DbType dbType =  propertyMap.GetColumnMap().DataType  ;
					outParam = new QueryParameter(paramName, dbType, value );
					break; // TODO: HOW??? To fix for composite identities??????
					// (possibly by traversing the propertypath as many times as the final property has columns ???)
					// (something like WrapColumn in sql engine does..)
				}				
			}
			if (outParam == null)
			{
				outParam = new QueryParameter(paramName, inParam.DbType,  inParam.Value);
			}
			return outParam;								
		}
 public Task <TEntity> FindByQuery(IQueryParameter repository, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }
Example #22
0
 /// <summary>
 /// Loads the specified URI.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TParam">The type of the t parameter.</typeparam>
 /// <param name="uri">The URI.</param>
 /// <param name="param">The parameter.</param>
 /// <returns>T.</returns>
 public T Load <T, TParam>(Href <T> uri, IQueryParameter <TParam> param) where T : class, ICrestResource <T>
 {
     return(LoadAsync(uri, param).Result);
 }
Example #23
0
 /// <summary>
 /// Loads the asynchronous.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <typeparam name="TParam">The type of the t parameter.</typeparam>
 /// <param name="uri">The URI.</param>
 /// <param name="param">The parameter.</param>
 /// <returns>Task&lt;T&gt;.</returns>
 public Task <T> LoadAsync <T, TParam>(Href <T> uri, IQueryParameter <TParam> param) where T : class, ICrestResource <T>
 {
     return(uri == null
         ? Task.FromResult(default(T))
         : getAsync <T>((createQueryString(uri.Uri, QueryParameters.GetParameterName <TParam>(), param.Uri.ToString()))));
 }
 public bool Equals(IQueryParameter other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other.Name, Name);
 }
Example #25
0
        private static object ParseValue(IQueryParameter parameter)
        {
            if (parameter.Value == null)
            {
                return DBNull.Value;
            }

            if (parameter.Field.BindToField != null && parameter.Field.Info.PropertyType == parameter.Value.GetType())
            {
                return parameter.Field.BindToField.GetFieldFinalValue(parameter.Value);
            }

            return parameter.Value;
        }
Example #26
0
 public static U FirstOrDefault <T, U>(this IQueryable <T> queryable, IQueryParameter <T, U> queryParameter) where T : class
 {
     return(queryable.GetQueryable(queryParameter).FirstOrDefault());
 }
Example #27
0
 /// <summary>
 /// 初始化一个<see cref="Query{TEntity}"/>类型的实例
 /// </summary>
 /// <param name="queryParameter">查询参数</param>
 public Query(IQueryParameter queryParameter) : base(queryParameter)
 {
 }
 public string FromParameterValue(IQueryParameter parameter)
 {
     return Convert.ToString(parameter.Value);
 }
Example #29
0
 public static List <U> Get <T, U>(this IQueryable <T> queryable, IQueryParameter <T, U> queryParameter) where T : class
 {
     return(queryable.GetQueryable(queryParameter).ToList());
 }
Example #30
0
        private static IQueryable <U> GetQueryable <T, U>(this IQueryable <T> queryable, IQueryParameter <T, U> queryParameter) where T : class
        {
            var query = queryParameter.Includes.Aggregate(
                queryable.Where(queryParameter.WhereClause ?? ((x) => true)),
                (current, include) => current.Include(include)).AsQueryable();

            var isOrdered = queryParameter.OrderExpressions.Any();

            if (isOrdered)
            {
                for (var i = 0; i < queryParameter.OrderExpressions.Count; i++)
                {
                    query = queryParameter.OrderExpressions[i].Order(query, i == 0);
                }
            }

            if (queryParameter.PageSize.HasValue)
            {
                if (!isOrdered)
                {
                    query = query.OrderBy(x => 1);
                }

                query = query
                        .Skip(queryParameter.Skip)
                        .Take(queryParameter.PageSize.Value);

                //query = query
                //    .Skip(() => queryParameter.Skip)
                //    .Take(() => queryParameter.PageSize.Value);
            }

            IQueryable <U> projectedQuery;

            if (queryParameter.Projection != null)
            {
                projectedQuery = query.Select(queryParameter.Projection);
            }
            else
            {
                projectedQuery = query as IQueryable <U>;
            }

            if (queryParameter.IsDistinct)
            {
                projectedQuery = projectedQuery.Distinct();
            }

            return(projectedQuery);
        }
Example #31
0
 public static Task <U> FirstOrDefaultAsync <T, U>(this IQueryable <T> queryable, IQueryParameter <T, U> queryParameter) where T : class
 {
     return(queryable.GetQueryable(queryParameter).FirstOrDefaultAsync());
 }
Example #32
0
		/// <summary>
		///     Creates a generic query part that can be used for any query
		/// </summary>
		/// <param name="prefix"></param>
		public GenericQueryPart(string prefix)
		{
			Debug.Assert(prefix != null, "prefix != null");
			Prefix = prefix;
			QueryParameters = new IQueryParameter[0];
		}
Example #33
0
 /// <summary>
 /// </summary>
 /// <param name="query"></param>
 public QueryFactoryResult(string query)
 {
     Query      = query;
     Parameters = new IQueryParameter[0];
 }
Example #34
0
 /// <summary>
 ///     Creates a generic query part that can be used for any query
 /// </summary>
 /// <param name="prefix"></param>
 public GenericQueryPart(string prefix)
 {
     Debug.Assert(prefix != null, "prefix != null");
     Prefix          = prefix;
     QueryParameters = new IQueryParameter[0];
 }
 public string FromParameterValue(IQueryParameter parameter)
 {
     return(Convert.ToString(parameter.Value));
 }
Example #36
0
 public static Task <List <U> > GetAsync <T, U>(this IQueryable <T> queryable, IQueryParameter <T, U> queryParameter) where T : class
 {
     return(queryable.GetQueryable(queryParameter).ToListAsync());
 }
Example #37
0
 private static bool InvalidDateTime(IQueryParameter parameter)
 {
     return parameter.type == typeof(DateTime) && ((DateTime)parameter.Value).Year < 1753;
 }