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)); }
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); }
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); }
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); }
private static void GetTest_Run(IFaunaClient client, ref Expr lastQuery) { var q = client.Get <ReferenceModel>("test1"); var manual = Get(Ref("test1")); Assert.IsTrue(lastQuery.Equals(manual)); }
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)); }
public static IQueryable <T> Query <T>(this IFaunaClient client, Expression <Func <T, bool> > selector) { if (!(selector.Body is BinaryExpression binary)) { throw new ArgumentException("Index selector must be binary expression."); } return(new FaunaQueryableData <T>(client, Map(WalkSelector(binary), arg0 => Language.Get(arg0)))); }
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 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)); }
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)); }
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 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)); }
private static void UpdateTest_Run(IFaunaClient client, ref Expr lastQuery) { var model = new ReferenceModel { Id = "testId", Indexed1 = "test1", Indexed2 = "test2" }; var q = client.Update(model).Result; var manual = Update(Ref(model.Id), model.ToFaunaObj()); Assert.IsTrue(lastQuery.Equals(manual)); }
private static void CreateTest_Run(IFaunaClient client, ref Expr lastQuery) { var model = new ReferenceModel { Indexed1 = "test1", Indexed2 = "test2" }; var q = client.Create(model).Result; var manual = Create(Ref(Class("reference_model"), 1), Obj("data", model.ToFaunaObj())); Assert.IsTrue(lastQuery.Equals(manual)); }
private static void DeleteTest_Run(IFaunaClient client, ref Expr lastQuery) { var model = new ReferenceModel { Id = "testId", Indexed1 = "test1", Indexed2 = "test2" }; var q = client.Delete(model); var manual = Delete(Ref(model.Id)); Assert.IsTrue(lastQuery.Equals(manual)); }
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)); }
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)); }
private static void UpsertTest_Run(IFaunaClient client, ref Expr lastQuery) { var model = new ReferenceModel { Id = "testId", Indexed1 = "test1", Indexed2 = "test2" }; var q = client.Upsert(model); var manual = If(Exists(Ref(model.Id)), Update(Ref(model.Id), model.ToFaunaObj()), Create(Ref(Class("reference_model"), 1), model.ToFaunaObj())); Assert.IsTrue(lastQuery.Equals(manual)); }
private static void UpsertCompositeIndexWithArgsTest_Run(IFaunaClient client, ref Expr lastQuery) { var model = new ReferenceModel { Indexed1 = "test1", Indexed2 = "test2" }; var q = client.Upsert(model, a => a.CompositeIndex, "test1", "test2"); var matchExpr = Match(Index("composite_index"), "test1", "test2"); var manual = If(Exists(matchExpr), Map(matchExpr, a => Update(a, model.ToFaunaObj())), Create(model.GetClassRef(), model.ToFaunaObj())); Assert.IsTrue(lastQuery.Equals(manual)); }
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); }
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)); }
private static void UpsertBooleanExpressionTest_Run(IFaunaClient client, ref Expr lastQuery) { var model = new ReferenceModel { Indexed1 = "test1", Indexed2 = "test2" }; var q = client.Upsert(model, a => a.Indexed1 == "test1"); var matchExpr = Match(Index("index_1"), "test1"); var manual = If(Exists(matchExpr), Map(matchExpr, a => Update(a, model.ToFaunaObj())), Create(model.GetClassRef(), model.ToFaunaObj())); Assert.IsTrue(lastQuery.Equals(manual)); }
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)); }
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)); }
internal static IDbContext CreateMappingContext(IFaunaClient mock) { var builder = DbContext.StartBuilding(mock); builder.RegisterMapping <ReferenceModelMapping>(); builder.RegisterMapping <PrimitivesReferenceModelMapping>(); builder.RegisterMapping <ReferenceTypesReferenceModelMapping>(); builder.RegisterMapping <ValueTypesReferenceModelMapping>(); builder.RegisterMapping <NamedPropertyModelMapping>(); builder.RegisterMapping <ModelWithUnmappedReferenceMapping>(); builder.RegisterMapping <SupportedCustomCollectionModelMapping>(); builder.RegisterMapping <SupportedCustomCollectionModelMapping2>(); builder.RegisterMapping <UnsupportedCustomCollectionModelMapping>(); builder.RegisterMapping <UnsupportedCustomCollectionModelMapping2>(); builder.RegisterMapping <UnsupportedCustomCollectionModelMapping3>(); builder.RegisterMapping <IncludeModelMapping>(); builder.RegisterMapping <ConstructorTestModelMapping>(); return(builder.Build()); }
internal static IDbContext CreateAttributeContext(IFaunaClient mock) { var builder = DbContext.StartBuilding(mock); builder.RegisterReferenceModel <ReferenceModel>(); builder.RegisterReferenceModel <PrimitivesReferenceModel>(); builder.RegisterReferenceModel <ReferenceTypesReferenceModel>(); builder.RegisterReferenceModel <ValueTypesReferenceModel>(); builder.RegisterReferenceModel <NamedPropertyModel>(); builder.RegisterReferenceModel <ModelWithUnmappedReference>(); builder.RegisterReferenceModel <SupportedCustomCollectionModel>(); builder.RegisterReferenceModel <SupportedCustomCollectionModel2>(); builder.RegisterReferenceModel <UnsupportedCustomCollectionModel>(); builder.RegisterReferenceModel <UnsupportedCustomCollectionModel2>(); builder.RegisterReferenceModel <UnsupportedCustomCollectionModel3>(); builder.RegisterReferenceModel <IncludeModel>(); builder.RegisterReferenceModel <ConstructorTestModel>(); return(builder.Build()); }
public static Task Delete(this IFaunaClient client, IReferenceType obj) { return(client.Delete(obj.Id)); }
public static Task Delete(this IFaunaClient client, string id) { return(client.Query(Language.Delete(Ref(id)))); }
public DbContextBuilder(IFaunaClient client) { _client = client; }
public static Task <T> Upsert <T>(this IFaunaClient client, T obj) where T : IReferenceType { return(client.Upsert(obj, obj.Id)); }