-
-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to query for event data for a subset of event types. Closes G…
- Loading branch information
1 parent
263a647
commit 7871c6c
Showing
5 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using JasperFx.Core.Reflection; | ||
using Marten.Linq.Members; | ||
using Marten.Linq.Parsing; | ||
using Marten.Linq.Parsing.Methods; | ||
using Weasel.Postgresql.SqlGeneration; | ||
|
||
namespace Marten.Events; | ||
|
||
public static class LinqExtensions | ||
{ | ||
/// <summary> | ||
/// LINQ filter to select only a specified set of event types | ||
/// </summary> | ||
/// <param name="e"></param> | ||
/// <param name="types"></param> | ||
/// <returns></returns> | ||
public static bool EventTypesAre(this IEvent e, params Type[] types) | ||
{ | ||
return e.Data.GetType().IsOneOf(types); | ||
} | ||
} | ||
|
||
internal class EventTypesAreParser: IMethodCallParser | ||
{ | ||
public bool Matches(MethodCallExpression expression) | ||
{ | ||
return expression.Method.Name == nameof(LinqExtensions.EventTypesAre) && expression.Method.DeclaringType == typeof(LinqExtensions); | ||
} | ||
|
||
public ISqlFragment Parse(IQueryableMemberCollection memberCollection, IReadOnlyStoreOptions options, | ||
MethodCallExpression expression) | ||
{ | ||
var types = (Type[])expression.Arguments.Last().Value(); | ||
var typeNames = types.Select(x => options.Events.As<EventGraph>().EventMappingFor(x).EventTypeName).ToArray(); | ||
|
||
var queryableMember = memberCollection.MemberFor(nameof(IEvent.EventTypeName)); | ||
return new IsOneOfFilter(queryableMember, new CommandParameter(typeNames)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters