Skip to content

Commit

Permalink
add traversal linq extentions
Browse files Browse the repository at this point in the history
  • Loading branch information
ra0o0f committed Oct 8, 2016
1 parent 5d630d3 commit e1085ed
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 3 deletions.
17 changes: 17 additions & 0 deletions src/ArangoDB.Client/Data/TraversalData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArangoDB.Client.Data
{
public class TraversalData<TVertex, TEdge>
{
public TVertex Vertex { get; set; }

public TEdge Edge { get; set; }

public IList<TraversalPathData<TVertex, TEdge>> Path { get; set; }
}
}
15 changes: 15 additions & 0 deletions src/ArangoDB.Client/Data/TraversalPathData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArangoDB.Client.Data
{
public class TraversalPathData<TVertex, TEdge>
{
public TVertex Vertices { get; set; }

public TEdge Edges { get; set; }
}
}
71 changes: 69 additions & 2 deletions src/ArangoDB.Client/Extentions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using ArangoDB.Client.Data;
using ArangoDB.Client.Query;
using ArangoDB.Client.Query;
using ArangoDB.Client.Query.Clause;
using System;
using System.Collections.Concurrent;
Expand Down Expand Up @@ -253,7 +252,7 @@ internal static IAqlModifiable<TSource> InternalUpsert<TSource, TOld>(this IQuer
Expression.Constant(updateType)
)) as IAqlModifiable<TSource>;
}

public static IAqlModifiable<TSource> Insert<TSource>(this IQueryable<TSource> source)
{
return Insert(source, null);
Expand Down Expand Up @@ -392,5 +391,73 @@ public static IQueryable<TSource> Filter<TSource>(this IQueryable<TSource> sourc
source.Expression,
Expression.Quote(predicate)));
}

[ExtentionIdentifier("Graph")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> Graph<TVertex, TEdge>(this IQueryable source, string graphName)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("Graph", typeof(TVertex), typeof(TEdge)),
source.Expression,
Expression.Constant(graphName))) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}

[ExtentionIdentifier("Edges")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> Edges<TVertex, TEdge>(this IQueryable source, params string[] collectionNames)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("Edges", typeof(TVertex), typeof(TEdge)),
source.Expression,
Expression.Constant(collectionNames))) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}

[ExtentionIdentifier("Depth")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> Depth<TVertex, TEdge>(this ITraversalQueryable<TraversalData<TVertex, TEdge>> source, int min, int max)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("Depth", typeof(TVertex), typeof(TEdge)),
source.Expression,
Expression.Constant(min),
Expression.Constant(max))) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}

[ExtentionIdentifier("InBound")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> InBound<TVertex, TEdge>(this ITraversalQueryable<TraversalData<TVertex, TEdge>> source)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("InBound", typeof(TVertex), typeof(TEdge)),
source.Expression)) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}

[ExtentionIdentifier("OutBound")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> OutBound<TVertex, TEdge>(this ITraversalQueryable<TraversalData<TVertex, TEdge>> source)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("OutBound", typeof(TVertex), typeof(TEdge)),
source.Expression)) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}

[ExtentionIdentifier("AnyDirection")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> AnyDirection<TVertex, TEdge>(this ITraversalQueryable<TraversalData<TVertex, TEdge>> source)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("AnyDirection", typeof(TVertex), typeof(TEdge)),
source.Expression)) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}

[ExtentionIdentifier("StartVertex")]
public static ITraversalQueryable<TraversalData<TVertex, TEdge>> StartVertex<TVertex, TEdge>(this ITraversalQueryable<TraversalData<TVertex, TEdge>> source, string vertex)
{
return source.Provider.CreateQuery<TraversalData<TVertex, TEdge>>(
Expression.Call(
FindExtention("StartVertex", typeof(TVertex), typeof(TEdge)),
source.Expression,
Expression.Constant(vertex))) as ITraversalQueryable<TraversalData<TVertex, TEdge>>;
}
}
}
18 changes: 18 additions & 0 deletions src/ArangoDB.Client/Interface/ITraversalQueryable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArangoDB.Client
{
public interface ITraversalQueryable : IQueryable, IOrderedQueryable
{

}

public interface ITraversalQueryable<T> : ITraversalQueryable, IQueryable<T>, IOrderedQueryable<T>
{

}
}
2 changes: 1 addition & 1 deletion src/ArangoDB.Client/Query/ArangoQueryable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace ArangoDB.Client.Query
{
public class ArangoQueryable<T> : QueryableBase<T>, IAqlModifiable<T>, IAqlModifiable
public class ArangoQueryable<T> : QueryableBase<T>, IAqlModifiable<T>, IAqlModifiable, ITraversalQueryable<T>, ITraversalQueryable
{
IArangoDatabase db;

Expand Down

0 comments on commit e1085ed

Please sign in to comment.