public static IQuery Nor(QueryArray array)
 {
     return(new Query()
     {
         Key = "$nor",
         Value = array
     });
 }
 public static IQuery And(QueryArray array)
 {
     return(new Query()
     {
         Key = "$and",
         Value = array
     });
 }
        public static IQuery Exclude(QueryArray values)
        {
            QueryGroup queryGroup = new QueryParams(values.ToDictionary(x => x, y => 0));

            return(new Query()
            {
                Key = "select",
                Value = queryGroup
            });
        }
        /*
         * public static IQuery Where(IEnumerable<KeyValuePair<string, object>> conditions)
         * {
         *      QueryGroup conditionsQueryGroup = new QueryGroup(conditions.Select(x => new Query(x.Key, Query.CastToQuery(x.Value))));
         *      return new Query()
         *      {
         *              Key = "where",
         *              Value = conditionsQueryGroup
         *      };
         * }
         */

        public static IQuery Select(QueryArray values)
        {
            Query trueQuery = 1;

            return(new Query()
            {
                Key = "select",
                Value = new QueryGroup(values.Select(x => new Query((x as Query).ValueAsVariable.ToString(), trueQuery)))
            });
        }
 public static IQuery NotContains(string key, QueryArray array)
 {
     return(new Query()
     {
         Key = key,
         Value = new Query()
         {
             Key = "$nin",
             Value = array
         }
     });
 }
        private static IQuery ConvertJTokenToQuery(JToken jToken)
        {
            if (jToken is JProperty jProperty)
            {
                if (jProperty.Type == JTokenType.Property)
                {
                    return(new Query(jProperty.Name, Query.CastToQuery(ConvertJTokenToQuery(jProperty.Value))));
                }
                else if (jProperty.Type == JTokenType.Object)
                {
                    return(new Query(jProperty.Name, ConvertJTokenToQuery(jProperty.Value)));
                }
                else
                {
                    new Query(jProperty.Name, Query.CastToQuery(ConvertJsonProperty(jProperty)));
                }
            }

            switch (jToken.Type)
            {
            case JTokenType.None:
            case JTokenType.Object:
            case JTokenType.Constructor:
            case JTokenType.Property:
                return(Query.CastToQuery(jToken));

            case JTokenType.Array:
                QueryArray queryArray = new QueryArray();
                foreach (var item in jToken)
                {
                    queryArray.Add(ConvertJTokenToQuery(item));
                }

                return(queryArray);

            case JTokenType.String:
            case JTokenType.Comment:
            case JTokenType.Guid:
            case JTokenType.Uri:
            case JTokenType.Raw:
                return(Query.CastToQuery(jToken.Value <string>()));

            case JTokenType.Integer:
            case JTokenType.Bytes:
                return(Query.CastToQuery(jToken.Value <int>()));

            case JTokenType.Float:
                return(Query.CastToQuery(jToken.Value <double>()));

            case JTokenType.Boolean:
                return(Query.CastToQuery(jToken.Value <bool>()));

            case JTokenType.Date:
                return(Query.CastToQuery(jToken.Value <DateTime>()));

            case JTokenType.TimeSpan:
                return(Query.CastToQuery(jToken.Value <TimeSpan>()));

            case JTokenType.Null:
            case JTokenType.Undefined:
                return(new Query());

            default:
                throw new ArgumentOutOfRangeException();
            }
        }