private static void MultiSelectorTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q1 = client.Query <ReferenceModel>(a => a.Indexed1 == "test1" && a.Indexed2 == "test2");
            var q2 = client.Query <ReferenceModel>(a => a.Indexed1 == "test1" || a.Indexed2 == "test2");

            var manual1 = Map(Intersection(Match(Index("index_1"), "test1"), Match(Index("index_2"), "test2")), arg0 => Get(arg0));
            var manual2 = Map(Union(Match(Index("index_1"), "test1"), Match(Index("index_2"), "test2")), arg0 => Get(arg0));

            q1.Provider.Execute <object>(q1.Expression);
            Assert.IsTrue(lastQuery.Equals(manual1));

            q2.Provider.Execute <object>(q2.Expression);
            Assert.IsTrue(lastQuery.Equals(manual2));
        }
Exemplo n.º 2
0
        private static void CatchAllWhereTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var i1 = 1;
            var i2 = 2;
            var q  = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Where(a =>
                                                                                     (a.Indexed1 == "test1" && a.Indexed2 != "test2") ||
                                                                                     (i2 > i1 && i1 < i2 && i1 <= i2 && i2 >= i1));

            var manual = Filter(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), arg1 => Or(
                                    And(
                                        EqualsFn(
                                            Select(Arr("data", "indexed1"), arg1), "test1"
                                            ),
                                        Not(EqualsFn(Select(Arr("data", "Indexed2"), arg1), "test2"))
                                        ),
                                    And(
                                        And(
                                            And(
                                                GT(2, 1),
                                                LT(1, 2)
                                                ),
                                            LTE(1, 2)
                                            ),
                                        GTE(2, 1)
                                        )
                                    ));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
Exemplo n.º 3
0
        public static async Task <T> Upsert <T>(this IFaunaClient client, T obj, string index, params Expr[] args)
        {
            var result = await client.Query(If(Exists(Match(Index(index), args)),
                                               Map(Match(Index(index), args), a => Language.Update(a, obj.ToFaunaObj())),
                                               Language.Create(obj.GetClassRef(), obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
Exemplo n.º 4
0
        public static async Task <T> Upsert <T>(this IFaunaClient client, T obj, string id)
        {
            var result = await client.Query(If(Exists(id),
                                               Language.Update(id, obj.ToFaunaObj()),
                                               Language.Create(obj.GetClassRef(), obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
Exemplo n.º 5
0
        public static async Task <T> Get <T>(this IFaunaClient client, string @ref)
        {
            var result = await client.Query(Language.Get(Ref(@ref)));

            return(typeof(IReferenceType).IsAssignableFrom(typeof(T))
                ? result.To <T>().Value
                : result.To <FaunaResult <T> >().Value.Data);
        }
        private static void RefQueryTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>("ref1");

            var manual = Get(Ref("ref1"));

            q.Provider.Execute <object>(q.Expression);
            Assert.IsTrue(lastQuery.Equals(manual));
        }
Exemplo n.º 7
0
        private static void FromRefPaginateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q      = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Paginate(size: 5, fromRef: "testRef");
            var manual = Paginate(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), size: 5, after: Ref("testRef"));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
        private static void CompositeWithTupleTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.CompositeIndex == Tuple.Create("test1", "test2"));

            var manual = Map(Match(Index("composite_index"), "test1", "test2"), arg0 => Get(arg0));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
Exemplo n.º 9
0
        private static void AllOptionsPaginateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Paginate(size: 5, timeStamp: new DateTime(2017, 1, 1), fromRef: "testRef", sortDirection: ListSortDirection.Descending);

            var manual = Paginate(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), size: 5, ts: Time(new DateTime(2017, 1, 1).ToString("O")), before: Ref("testRef"));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
        private static void SingleBooleanSelectorTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test2");

            q.Provider.Execute <object>(q.Expression);
            var parsed = lastQuery;
            var manual = Map(Match(Index("index_1"), "test2"), arg0 => Get(arg0));

            Assert.IsTrue(parsed.Equals(manual));
        }
Exemplo n.º 11
0
        private static void DateTimePaginateTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Paginate(size: 5, timeStamp: new DateTime(2017, 1, 1));

            var manual = Paginate(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), size: 5, ts: Time(new DateTime(2017, 1, 1).ToString("O")));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
Exemplo n.º 12
0
        private static void MemberInitTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Where(a => a == new ReferenceModel {
                Indexed1 = "test1"
            });
            var manual = Filter(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)), arg1 => EqualsFn(arg1, Obj("indexed1", "test1", "Indexed2", Null())));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
Exemplo n.º 13
0
        private static void SelectStringConcatTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Select(a => a.Indexed1 + "concat");

            var manual = Map(Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0)),
                             arg1 => Concat(Arr(Select(Arr("data", "indexed1"), arg1), "concat")));

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(lastQuery.Equals(manual));
        }
Exemplo n.º 14
0
        public static void ChainedQueryTest_Run(IFaunaClient client, ref Expr lastQuery)
        {
            var q = client.Query <ReferenceModel>(a => a.Indexed1 == "test1").Where(a => a.Indexed1 == "test1").Select(a => a.Indexed1);

            var selectorManual = Map(Match(Index("index_1"), "test1"), arg0 => Get(arg0));
            var filterManual   = Filter(selectorManual, arg1 => EqualsFn(Select(Arr("data", "indexed1"), arg1), "test1"));
            var selectManual   = Map(filterManual, arg2 => Select(Arr("data", "indexed1"), arg2));
            var manual         = selectManual;

            q.Provider.Execute <object>(q.Expression);

            Assert.IsTrue(manual.Equals(lastQuery));
        }
Exemplo n.º 15
0
        public static async Task <T> Upsert <T>(this IFaunaClient client, T obj, Expression <Func <T, bool> > indices)
        {
            if (!(indices.Body is BinaryExpression binary))
            {
                throw new ArgumentException("Index selector must be binary expression.");
            }
            var selectorExpr = WalkSelector(binary);

            var result = await client.Query(If(Exists(selectorExpr), Map(selectorExpr, a => Language.Update(a, obj.ToFaunaObj())),
                                               Language.Create(obj.GetClassRef(), obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
Exemplo n.º 16
0
        public static IQueryable <T> Query <T>(this IFaunaClient client, Expression <Func <T, object> > index, params Expr[] args)
        {
            if (!(index.Body is MemberExpression member))
            {
                throw new ArgumentException("Index selector must be a member.");
            }

            var propInfo  = member.GetPropertyInfo();
            var indexAttr = propInfo.GetCustomAttribute <IndexedAttribute>();

            if (indexAttr == null)
            {
                throw new ArgumentException("Can't use unindexed property as selector!", nameof(index));
            }
            var indexName = indexAttr.Name;

            return(client.Query <T>(indexName, args));
        }
        public TResult Execute <TResult>(Expression expression)
        {
            var result = _client.Query(FaunaQueryParser.Parse(_selector, expression)).Result;

            return(result.To <TResult>().Value);
        }
Exemplo n.º 18
0
        public static async Task <T> Create <T>(this IFaunaClient client, T obj)
        {
            var result = await client.Query(Language.Create(obj.GetClassRef(), Obj("data", obj.ToFaunaObj())));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
Exemplo n.º 19
0
        public static async Task <T> Update <T>(this IFaunaClient client, T obj, string id)
        {
            var result = await client.Query(Language.Update(Ref(id), obj.ToFaunaObj()));

            return(obj is IReferenceType?result.To <T>().Value : result.To <FaunaResult <T> >().Value.Data);
        }
Exemplo n.º 20
0
 public static Task Delete(this IFaunaClient client, string id)
 {
     return(client.Query(Language.Delete(Ref(id))));
 }
Exemplo n.º 21
0
        public virtual async Task <T> Query <T>(Expr query)
        {
            var result = await _client.Query(query);

            return(this.Decode <T>(result));
        }