Fauna v10 .NET/C# Driver 0.5.0-beta
 
Loading...
Searching...
No Matches
IQuerySource.cs
Go to the documentation of this file.
1using System.Linq.Expressions;
2using Fauna.Core;
3using Fauna.Types;
4
5namespace Fauna.Linq;
6
7public interface IQuerySource
8{
9 // TODO(matt) use an API-specific exception in-line with what other LINQ
10 // libraries do.
11 internal static Exception Fail(Expression? expr) =>
12 Fail($"Unsupported {expr?.NodeType} expression: {expr}");
13
14 internal static Exception Fail(string op, string msg) =>
15 Fail($"Unsupported method call `{op}`: {msg}");
16
17 internal static Exception Fail(string msg) => new NotSupportedException(msg);
18}
19
20public interface IQuerySource<T> : IQuerySource
21{
22 // Core execution
23
24 public IAsyncEnumerable<Page<T>> PaginateAsync(QueryOptions? queryOptions = null, CancellationToken cancel = default);
25 public IAsyncEnumerable<T> ToAsyncEnumerable(CancellationToken cancel = default);
26 public IEnumerable<T> ToEnumerable();
27
28 // Composition methods
29
32 public IQuerySource<T> OrderBy<K>(Expression<Func<T, K>> keySelector);
34 public IQuerySource<T> OrderByDescending<K>(Expression<Func<T, K>> keySelector);
36 public IQuerySource<R> Select<R>(Expression<Func<T, R>> selector);
37 // public IQuerySource<R> SelectMany<R>(Expression<Func<T, IQuerySource<R>>> selector);
38 public IQuerySource<T> Skip(int count);
39 public IQuerySource<T> Take(int count);
40 public IQuerySource<T> Where(Expression<Func<T, bool>> predicate);
41
42 // Terminal result methods
43
44 // public R Aggregate<A, R>(A seed, Expression<Func<A, T, A>> accum, Func<A, R> selector);
45 // public Task<R> AggregateAsync<A, R>(A seed, Expression<Func<A, T, A>> accum, Func<A, R> selector);
46
47 // // not IQueryable
48 // public R Fold<R>(R seed, Expression<Func<R, T, R>> accum);
49 // public Task<R> FoldAsync<R>(R seed, Expression<Func<R, T, R>> accum);
50
51 public bool All(Expression<Func<T, bool>> predicate);
52 public Task<bool> AllAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
53
54 public bool Any();
55 public Task<bool> AnyAsync(CancellationToken cancel = default);
56
57 public bool Any(Expression<Func<T, bool>> predicate);
58 public Task<bool> AnyAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
59
60 public int Count();
61 public Task<int> CountAsync(CancellationToken cancel = default);
62
63 public int Count(Expression<Func<T, bool>> predicate);
64 public Task<int> CountAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
65
66 public T First();
67 public Task<T> FirstAsync(CancellationToken cancel = default);
68
69 public T First(Expression<Func<T, bool>> predicate);
70 public Task<T> FirstAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
71
72 public T? FirstOrDefault();
73 public Task<T?> FirstOrDefaultAsync(CancellationToken cancel = default);
74
75 public T? FirstOrDefault(Expression<Func<T, bool>> predicate);
76 public Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
77
78 public T Last();
79 public Task<T> LastAsync(CancellationToken cancel = default);
80
81 public T Last(Expression<Func<T, bool>> predicate);
82 public Task<T> LastAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
83
84 public T? LastOrDefault();
85 public Task<T?> LastOrDefaultAsync(CancellationToken cancel = default);
86
87 public T? LastOrDefault(Expression<Func<T, bool>> predicate);
88 public Task<T?> LastOrDefaultAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
89
90 public long LongCount();
91 public Task<long> LongCountAsync(CancellationToken cancel = default);
92
93 public long LongCount(Expression<Func<T, bool>> predicate);
94 public Task<long> LongCountAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
95
96 public T Max();
97 public Task<T> MaxAsync(CancellationToken cancel = default);
98
99 public R Max<R>(Expression<Func<T, R>> selector);
100 public Task<R> MaxAsync<R>(Expression<Func<T, R>> selector, CancellationToken cancel = default);
101
102 // public T MaxBy<K>(Expression<Func<T, K>> selector);
103 // public Task<K> MaxByAsync<K>(Expression<Func<T, K>> selector, CancellationToken cancel = default);
104
105 public T Min();
106 public Task<T> MinAsync(CancellationToken cancel = default);
107
108 // public T MinBy<K>(Expression<Func<T, K>> selector);
109 // public Task<K> MinByAsync<K>(Expression<Func<T, K>> selector, CancellationToken cancel = default);
110
111 public R Min<R>(Expression<Func<T, R>> selector);
112 public Task<R> MinAsync<R>(Expression<Func<T, R>> selector, CancellationToken cancel = default);
113
114 public T Single();
115 public Task<T> SingleAsync(CancellationToken cancel = default);
116
117 public T Single(Expression<Func<T, bool>> predicate);
118 public Task<T> SingleAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
119
120 public T SingleOrDefault();
121 public Task<T> SingleOrDefaultAsync(CancellationToken cancel = default);
122
123 public T SingleOrDefault(Expression<Func<T, bool>> predicate);
124 public Task<T> SingleOrDefaultAsync(Expression<Func<T, bool>> predicate, CancellationToken cancel = default);
125
126 public int Sum(Expression<Func<T, int>> selector);
127 public Task<int> SumAsync(Expression<Func<T, int>> selector, CancellationToken cancel = default);
128
129 public long Sum(Expression<Func<T, long>> selector);
130 public Task<long> SumAsync(Expression<Func<T, long>> selector, CancellationToken cancel = default);
131
132 // public float Sum(Expression<Func<T, float>> selector);
133 // public Task<float> SumAsync(Expression<Func<T, float>> selector, CancellationToken cancel = default);
134
135 public double Sum(Expression<Func<T, double>> selector);
136 public Task<double> SumAsync(Expression<Func<T, double>> selector, CancellationToken cancel = default);
137
138 public double Average(Expression<Func<T, double>> selector);
139 public Task<double> AverageAsync(Expression<Func<T, double>> selector, CancellationToken cancel = default);
140
141 // Collection result methods
142
143 public List<T> ToList();
144 public Task<List<T>> ToListAsync(CancellationToken cancel = default);
145
146 public T[] ToArray();
147 public Task<T[]> ToArrayAsync(CancellationToken cancel = default);
148
149 public HashSet<T> ToHashSet();
150 public Task<HashSet<T>> ToHashSetAsync(CancellationToken cancel = default);
151
152 public HashSet<T> ToHashSet(IEqualityComparer<T>? comparer);
153 public Task<HashSet<T>> ToHashSetAsync(IEqualityComparer<T>? comparer, CancellationToken cancel = default);
154
155 public Dictionary<K, V> ToDictionary<K, V>(Func<T, K> getKey, Func<T, V> getValue) where K : notnull;
156 public Task<Dictionary<K, V>> ToDictionaryAsync<K, V>(Func<T, K> getKey, Func<T, V> getValue, CancellationToken cancel = default) where K : notnull;
157
158 public Dictionary<K, V> ToDictionary<K, V>(Func<T, K> getKey, Func<T, V> getValue, IEqualityComparer<K>? comparer) where K : notnull;
159 public Task<Dictionary<K, V>> ToDictionaryAsync<K, V>(Func<T, K> getKey, Func<T, V> getValue, IEqualityComparer<K>? comparer, CancellationToken cancel = default) where K : notnull;
160}
Represents the options for customizing Fauna queries.
bool All(Expression< Func< T, bool > > predicate)
int Sum(Expression< Func< T, int > > selector)
Task< T > LastAsync(CancellationToken cancel=default)
Task< long > LongCountAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
long LongCount(Expression< Func< T, bool > > predicate)
Task< T[]> ToArrayAsync(CancellationToken cancel=default)
Task< T?> FirstOrDefaultAsync(CancellationToken cancel=default)
IAsyncEnumerable< Page< T > > PaginateAsync(QueryOptions? queryOptions=null, CancellationToken cancel=default)
IQuerySource< T > Where(Expression< Func< T, bool > > predicate)
R Max< R >(Expression< Func< T, R > > selector)
Task< T > LastAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
double Average(Expression< Func< T, double > > selector)
HashSet< T > ToHashSet(IEqualityComparer< T >? comparer)
IQuerySource< T > Distinct()
Task< T > FirstAsync(CancellationToken cancel=default)
IAsyncEnumerable< T > ToAsyncEnumerable(CancellationToken cancel=default)
IQuerySource< T > OrderByDescending< K >(Expression< Func< T, K > > keySelector)
long Sum(Expression< Func< T, long > > selector)
T? FirstOrDefault(Expression< Func< T, bool > > predicate)
Task< bool > AnyAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
Task< int > CountAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
int Count(Expression< Func< T, bool > > predicate)
Task< T > FirstAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
IQuerySource< T > Take(int count)
T Last(Expression< Func< T, bool > > predicate)
Task< T > SingleAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
Task< R > MinAsync< R >(Expression< Func< T, R > > selector, CancellationToken cancel=default)
IQuerySource< T > Reverse()
T Single(Expression< Func< T, bool > > predicate)
Dictionary< K, V > ToDictionary< K, V >(Func< T, K > getKey, Func< T, V > getValue)
Task< R > MaxAsync< R >(Expression< Func< T, R > > selector, CancellationToken cancel=default)
Task< double > AverageAsync(Expression< Func< T, double > > selector, CancellationToken cancel=default)
Task< int > SumAsync(Expression< Func< T, int > > selector, CancellationToken cancel=default)
T First(Expression< Func< T, bool > > predicate)
Task< T > MaxAsync(CancellationToken cancel=default)
IQuerySource< T > Skip(int count)
Task< Dictionary< K, V > > ToDictionaryAsync< K, V >(Func< T, K > getKey, Func< T, V > getValue, CancellationToken cancel=default)
Task< T > SingleOrDefaultAsync(CancellationToken cancel=default)
Task< HashSet< T > > ToHashSetAsync(CancellationToken cancel=default)
Task< T?> LastOrDefaultAsync(CancellationToken cancel=default)
Task< long > SumAsync(Expression< Func< T, long > > selector, CancellationToken cancel=default)
IQuerySource< R > Select< R >(Expression< Func< T, R > > selector)
HashSet< T > ToHashSet()
IQuerySource< T > OrderDescending()
Task< List< T > > ToListAsync(CancellationToken cancel=default)
Task< bool > AllAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
double Sum(Expression< Func< T, double > > selector)
IQuerySource< T > OrderBy< K >(Expression< Func< T, K > > keySelector)
Task< T > SingleAsync(CancellationToken cancel=default)
Task< long > LongCountAsync(CancellationToken cancel=default)
Task< T > MinAsync(CancellationToken cancel=default)
Task< T?> FirstOrDefaultAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
R Min< R >(Expression< Func< T, R > > selector)
Task< T > SingleOrDefaultAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
T SingleOrDefault(Expression< Func< T, bool > > predicate)
IQuerySource< T > Order()
IEnumerable< T > ToEnumerable()
Task< int > CountAsync(CancellationToken cancel=default)
bool Any(Expression< Func< T, bool > > predicate)
T? LastOrDefault(Expression< Func< T, bool > > predicate)
Task< HashSet< T > > ToHashSetAsync(IEqualityComparer< T >? comparer, CancellationToken cancel=default)
Task< T?> LastOrDefaultAsync(Expression< Func< T, bool > > predicate, CancellationToken cancel=default)
Task< double > SumAsync(Expression< Func< T, double > > selector, CancellationToken cancel=default)
Task< bool > AnyAsync(CancellationToken cancel=default)