Skip to content

Commit 59ece60

Browse files
Add Firestore aggregate query bindings (#124)
* Add Firestore aggregate query bindings * Exercise Firestore aggregate backend callback * Assert Firestore aggregate count is nonzero
1 parent f55fdce commit 59ece60

4 files changed

Lines changed: 407 additions & 0 deletions

File tree

source/Firebase/CloudFirestore/ApiDefinition.cs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,73 @@ interface VectorValue
357357
NativeHandle Constructor (NSNumber [] array);
358358
}
359359

360+
// @interface FIRAggregateField : NSObject
361+
[DisableDefaultCtor]
362+
[BaseType (typeof (NSObject), Name = "FIRAggregateField")]
363+
interface AggregateField
364+
{
365+
// +(instancetype _Nonnull)aggregateFieldForCount;
366+
[Static]
367+
[Export ("aggregateFieldForCount")]
368+
AggregateField Count { get; }
369+
370+
// +(instancetype _Nonnull)aggregateFieldForSumOfField:(NSString * _Nonnull)field;
371+
[Static]
372+
[Export ("aggregateFieldForSumOfField:")]
373+
AggregateField Sum (string field);
374+
375+
// +(instancetype _Nonnull)aggregateFieldForSumOfFieldPath:(FIRFieldPath * _Nonnull)fieldPath;
376+
[Static]
377+
[Export ("aggregateFieldForSumOfFieldPath:")]
378+
AggregateField Sum (FieldPath fieldPath);
379+
380+
// +(instancetype _Nonnull)aggregateFieldForAverageOfField:(NSString * _Nonnull)field;
381+
[Static]
382+
[Export ("aggregateFieldForAverageOfField:")]
383+
AggregateField Average (string field);
384+
385+
// +(instancetype _Nonnull)aggregateFieldForAverageOfFieldPath:(FIRFieldPath * _Nonnull)fieldPath;
386+
[Static]
387+
[Export ("aggregateFieldForAverageOfFieldPath:")]
388+
AggregateField Average (FieldPath fieldPath);
389+
}
390+
391+
// typedef void (^FIRAggregateQuerySnapshotBlock)(FIRAggregateQuerySnapshot * _Nullable, NSError * _Nullable);
392+
delegate void AggregateQuerySnapshotHandler ([NullAllowed] AggregateQuerySnapshot snapshot, [NullAllowed] NSError error);
393+
394+
// @interface FIRAggregateQuery : NSObject
395+
[DisableDefaultCtor]
396+
[BaseType (typeof (NSObject), Name = "FIRAggregateQuery")]
397+
interface AggregateQuery
398+
{
399+
// @property (readonly, nonatomic) FIRQuery * _Nonnull query;
400+
[Export ("query", ArgumentSemantic.Strong)]
401+
Query Query { get; }
402+
403+
// -(void)aggregationWithSource:(FIRAggregateSource)source completion:(void (^ _Nonnull)(FIRAggregateQuerySnapshot * _Nullable, NSError * _Nullable))completion;
404+
[Async]
405+
[Export ("aggregationWithSource:completion:")]
406+
void GetAggregation (AggregateSource source, AggregateQuerySnapshotHandler completion);
407+
}
408+
409+
// @interface FIRAggregateQuerySnapshot : NSObject
410+
[DisableDefaultCtor]
411+
[BaseType (typeof (NSObject), Name = "FIRAggregateQuerySnapshot")]
412+
interface AggregateQuerySnapshot
413+
{
414+
// @property (readonly, nonatomic) FIRAggregateQuery * _Nonnull query;
415+
[Export ("query", ArgumentSemantic.Strong)]
416+
AggregateQuery Query { get; }
417+
418+
// @property (readonly, nonatomic) NSNumber * _Nonnull count;
419+
[Export ("count", ArgumentSemantic.Strong)]
420+
NSNumber Count { get; }
421+
422+
// -(id _Nonnull)valueForAggregateField:(FIRAggregateField * _Nonnull)aggregateField;
423+
[Export ("valueForAggregateField:")]
424+
NSObject GetValue (AggregateField aggregateField);
425+
}
426+
360427
// void (^)(id _Nullable result, NSError *_Nullable error)
361428
delegate void TransactionCompletionHandler ([NullAllowed] NSObject result, [NullAllowed] NSError error);
362429
// (nullable void (^)(FIRLoadBundleTaskProgress *_Nullable progress, NSError *_Nullable error)
@@ -783,6 +850,14 @@ interface Query
783850

784851
[Wrap ("EndingAt (CloudFirestoreHelper.GetNSObjects (fieldValues))")]
785852
Query EndingAt (object [] fieldValues);
853+
854+
// @property (readonly, nonatomic) FIRAggregateQuery * _Nonnull count;
855+
[Export ("count", ArgumentSemantic.Strong)]
856+
AggregateQuery Count { get; }
857+
858+
// -(FIRAggregateQuery * _Nonnull)aggregate:(NSArray<FIRAggregateField *> * _Nonnull)aggregateFields;
859+
[Export ("aggregate:")]
860+
AggregateQuery Aggregate (AggregateField [] aggregateFields);
786861
}
787862

788863
// @interface FIRQuerySnapshot : NSObject

source/Firebase/CloudFirestore/Enums.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ public enum FirestoreSource : ulong
4949
Cache
5050
}
5151

52+
[Native]
53+
public enum AggregateSource : ulong
54+
{
55+
Server
56+
}
57+
5258
[Native]
5359
public enum LoadBundleTaskState : long
5460
{

0 commit comments

Comments
 (0)