1using System.Collections.Immutable;
2using System.Diagnostics.CodeAnalysis;
3using System.Reflection;
4using System.Runtime.CompilerServices;
11 private bool _initialized =
false;
13 private IReadOnlyDictionary<Type, ICollection> _collections =
null!;
15 private Client _client =
null!;
20 internal Linq.LookupTable LookupTable {
get =>
new Linq.LookupTable(_ctx); }
25 _collections = collections.ToImmutableDictionary();
28 foreach (var col
in collections.Values)
30 ((Linq.QuerySource)col).SetContext(
this);
38 internal override Task<QuerySuccess<T>> QueryAsyncInternal<T>(
40 Serialization.ISerializer<T> serializer,
43 CancellationToken cancel)
45 CheckInitialization();
46 return _client.QueryAsyncInternal(query, serializer, ctx, queryOptions, cancel);
51 [AttributeUsage(AttributeTargets.Class)]
54 internal readonly
string Name;
64 public string Name {
get; }
70 public string Name {
get; }
71 public Type
DocType {
get => typeof(Doc); }
75 var nameAttr = this.GetType().GetCustomAttribute<
NameAttribute>();
76 Name = nameAttr?.Name ?? typeof(Doc).Name;
77 SetQuery<Doc>(Linq.IntermediateQueryHelpers.CollectionAll(
this));
82 protected IndexCall Index(
string? name =
null, [CallerMemberName]
string?
auto =
null)
84 if (name is
null &&
auto is not
null)
86 name = FieldName.Canonical(
auto);
89 if (
string.IsNullOrEmpty(name))
90 throw new ArgumentException($
"{nameof(name)} cannot be null or empty.");
98 private readonly
string _name;
121 public interface IIndex : Linq.IQuerySource
142 SetQuery<Doc>(Linq.IntermediateQueryHelpers.CollectionIndex(
this));
170 public T
Call(
object a1,
object a2) =>
Call(
new[] { a1, a2 });
172 public T
Call(
object a1,
object a2,
object a3) =>
Call(
new[] { a1, a2, a3 });
182 public async Task<T>
CallAsync(
object a1,
object a2,
object a3) => await
CallAsync(
new[] { a1, a2, a3 });
186 var q = Linq.IntermediateQueryHelpers.Function(
Name, args);
187 return (await _ctx.QueryAsync<T>(q)).Data;
194 var fnName = name ==
"" ? callerName : name;
200 CheckInitialization();
201 return (Col)_collections[typeof(Col)];
204 private void CheckInitialization()
208 throw new InvalidOperationException(
209 "Uninitialized context. DataContext sub-classes must be instantiated using a client's .DataContext() method.");
The base class for Client and DataContext.
Represents a client for interacting with a Fauna.
Index< Doc > Call(object a1, object a2, object a3)
Index< Doc > Call(object a1)
IndexCall(ICollection coll, string name, DataContext ctx)
Index< Doc > Call(object a1, object a2)
Index< Doc > Call(object[] args)
IndexCall Index(string? name=null, [CallerMemberName] string? auto=null)
async Task< T > CallAsync()
T Call(object a1, object a2, object a3)
async Task< T > CallAsync(object a1, object a2)
T Call(object a1, object a2)
async Task< T > CallAsync(object a1)
FunctionCall(string name, DataContext ctx)
async Task< T > CallAsync(object a1, object a2, object a3)
async Task< T > CallAsync(object[] args)
NameAttribute(string name)
FunctionCall< T > Fn< T >(string name="", [CallerMemberName] string callerName="")
Col GetCollection< Col >()
A class representing the mapping context to be used during serialization and deserialization.
Represents the abstract base class for constructing FQL queries.
Represents the options for customizing Fauna queries.