Exemple #1
0
        public IEnumerable <T> ExecuteCollection <T>(QueryModel queryModel)
        {
            var visitor = new RethinkDbQueryModelVisitor(table);

            visitor.VisitQueryModel(queryModel);

            var query = visitor.Query;

            ProcessQuery(query);

            if (typeof(T).GetTypeInfo().IsGenericType&& typeof(T).GetGenericTypeDefinition() == typeof(IGrouping <,>))
            {
                return(typeof(RethinkQueryExecutor)
                       .GetMethod(nameof(DeserializeGrouping),
                                  BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly)
                       .MakeGenericMethod(
                           typeof(T).GetGenericArguments()[0],
                           typeof(T).GetGenericArguments()[1])
                       .Invoke(null, new object[]
                {
                    query.Run(connection) as JArray
                }) as IEnumerable <T>);
            }

            if (query is Get)
            {
                return(new List <T>
                {
                    query.RunResult <T>(connection)
                });
            }

            return(query.RunResult <List <T> >(connection));
        }
Exemple #2
0
        public T ExecuteSingle <T>(QueryModel queryModel, bool returnDefaultWhenEmpty)
        {
            var visitor = new RethinkDbQueryModelVisitor(table);

            visitor.VisitQueryModel(queryModel);

            var query = visitor.Query;

            ProcessQuery(query);

            try
            {
                return(query.RunResult <T>(connection));
            }
            catch (ReqlNonExistenceError ex)
            {
                if (ShouldReturnDefault(queryModel))
                {
                    return(default(T));
                }
                throw new InvalidOperationException(ex.Message);
            }
        }
Exemple #3
0
        public T ExecuteScalar <T>(QueryModel queryModel)
        {
            var visitor = new RethinkDbQueryModelVisitor(table);

            visitor.VisitQueryModel(queryModel);

            var query = visitor.Query;

            ProcessQuery(query);

            var result = query.Run(connection);

            if (queryModel.ResultOperators.FirstOrDefault() is AnyResultOperator)
            {
                return(result > 0);
            }
            if (queryModel.ResultOperators.FirstOrDefault() is AllResultOperator)
            {
                return(result == 0);
            }

            return((T)result);
        }