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