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

            return(new Query()
            {
                Key = "select",
                Value = queryGroup
            });
        }
Exemplo n.º 4
0
        /*
         * 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)))
            });
        }
Exemplo n.º 5
0
 public static IQuery NotContains(string key, QueryArray array)
 {
     return(new Query()
     {
         Key = key,
         Value = new Query()
         {
             Key = "$nin",
             Value = array
         }
     });
 }
Exemplo n.º 6
0
        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();
            }
        }