-
Notifications
You must be signed in to change notification settings - Fork 4k
feat(firestore): count()
feature for counting documents without retrieving documents.
#9699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
1f2ffc0
feat(firestore): count feature. Dart implementation
russellwheatley bb0a9f5
feat(firestore): count feature. Dart implementation.
russellwheatley 0e23ec0
feat(firestore): reverted iOS firestore change
russellwheatley 7735485
feat(firestore): count(). Wire up user facing code
russellwheatley 4dc2547
feat(firestore): count(). Wire up web implementation
russellwheatley 1d130f7
feat(firestore): count(). clean up method channel & PI
russellwheatley e58846e
feat(firestore): count(). e2e test.
russellwheatley 926cf58
feat(firestore): remove static.
russellwheatley 1f25a58
feat(firestore): correct init of data
russellwheatley 371ed9d
feat(firestore): count() API. licenses and inline documentation
russellwheatley 467ce69
feat(firestore): expose Query on AggregateQuery
russellwheatley d25bca7
feat(firestore): count(). add unit test for user code
russellwheatley 0a4f218
feat(firestore): count(). universal code unit test
russellwheatley 36a1c99
feat(firestore): count(). unit tests
russellwheatley 4c71036
feat(firestore): update code comment
russellwheatley 93f612f
feat(firestore): count() API. iOS implementation
russellwheatley e5a860e
feat(firestore): count() API. format.
russellwheatley 68c2137
feat(firestore): count() API e2e skip android
russellwheatley 3fe511d
feat(firestore): count() API. expose query on snapshot
russellwheatley 585c82a
feat(firestore): count() API. format
russellwheatley 2893c80
feat(firestore): count() API. wording
russellwheatley bdc6889
feat(firestore): count() API. remove Firestore from test project
russellwheatley 3c87ec5
feat(ios): update swiftformat and add back curly brace
russellwheatley b312ec8
fix(firestore): add nanopb pod to example
russellwheatley 0a90db2
feat(firestore): implement android
russellwheatley 6343092
feat(firestore): update iOS count()
russellwheatley 4723bc7
test(firestore): update unit test
russellwheatley 958db10
Merge branch 'master' into @russell/firestore-count
russellwheatley dd93f0f
chore: rm nanopb from example app
russellwheatley 8f36e58
chore: rm foundation import
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
packages/cloud_firestore/cloud_firestore/lib/src/aggregate_query.dart
This file contains hidden or 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,12 @@ | ||
part of cloud_firestore; | ||
|
||
class AggregateQuery { | ||
AggregateQuery._(this._delegate) { | ||
AggregateQueryPlatform.verifyExtends(_delegate); | ||
russellwheatley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
final AggregateQueryPlatform _delegate; | ||
|
||
Future<AggregateQuerySnapshot> get({AggregateSource source = AggregateSource.server}) async { | ||
return AggregateQuerySnapshot._(await _delegate.get(source: source)); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/cloud_firestore/cloud_firestore/lib/src/aggregate_query_snapshot.dart
This file contains hidden or 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,10 @@ | ||
part of cloud_firestore; | ||
|
||
class AggregateQuerySnapshot { | ||
russellwheatley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
AggregateQuerySnapshot._(this._delegate) { | ||
AggregateQuerySnapshotPlatform.verifyExtends(_delegate); | ||
} | ||
final AggregateQuerySnapshotPlatform _delegate; | ||
|
||
int get count => _delegate.count; | ||
} |
This file contains hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
packages/cloud_firestore/cloud_firestore_platform_interface/lib/src/aggregate_source.dart
This file contains hidden or 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,3 @@ | ||
enum AggregateSource { | ||
russellwheatley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
server, | ||
} |
29 changes: 29 additions & 0 deletions
29
...d_firestore_platform_interface/lib/src/method_channel/method_channel_aggregate_query.dart
This file contains hidden or 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,29 @@ | ||
import 'package:cloud_firestore_platform_interface/src/method_channel/utils/source.dart'; | ||
russellwheatley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import 'package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_aggregate_query.dart'; | ||
|
||
import 'method_channel_firestore.dart'; | ||
import '../../cloud_firestore_platform_interface.dart'; | ||
import '../aggregate_source.dart'; | ||
import '../platform_interface/platform_interface_aggregate_query_snapshot.dart'; | ||
|
||
class MethodChannelAggregateQuery extends AggregateQueryPlatform { | ||
MethodChannelAggregateQuery(QueryPlatform query) : super(query); | ||
|
||
@override | ||
Future<AggregateQuerySnapshotPlatform> get({required AggregateSource source}) async { | ||
final Map<String, dynamic>? data = await MethodChannelFirebaseFirestore | ||
.channel | ||
.invokeMapMethod<String, dynamic>( | ||
'AggregateQuery#count', | ||
<String, dynamic>{ | ||
'query': query, | ||
'firestore': query.firestore, | ||
'source': getAggregateSourceString(source), | ||
}, | ||
); | ||
|
||
return AggregateQuerySnapshotPlatform( | ||
count: data!['count'] as int, | ||
); | ||
} | ||
} |
This file contains hidden or 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 |
---|---|---|
|
@@ -11,6 +11,7 @@ import 'package:cloud_firestore_platform_interface/src/internal/pointer.dart'; | |
import 'package:collection/collection.dart'; | ||
import 'package:flutter/services.dart'; | ||
|
||
import 'method_channel_aggregate_query.dart'; | ||
import 'method_channel_firestore.dart'; | ||
import 'method_channel_query_snapshot.dart'; | ||
import 'utils/source.dart'; | ||
|
@@ -212,6 +213,13 @@ class MethodChannelQuery extends QueryPlatform { | |
}); | ||
} | ||
|
||
@override | ||
AggregateQueryPlatform count() { | ||
return MethodChannelAggregateQuery( | ||
this, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have a styleguide for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't AFAIK, it just follows the same implementation style as the rest of the plugins. |
||
); | ||
} | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return runtimeType == other.runtimeType && | ||
|
This file contains hidden or 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
27 changes: 27 additions & 0 deletions
27
...ore_platform_interface/lib/src/platform_interface/platform_interface_aggregate_query.dart
This file contains hidden or 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,27 @@ | ||
import 'package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_aggregate_query_snapshot.dart'; | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
import '../../cloud_firestore_platform_interface.dart'; | ||
import '../aggregate_source.dart'; | ||
|
||
abstract class AggregateQueryPlatform extends PlatformInterface { | ||
AggregateQueryPlatform(this.query) : super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
/// Throws an [AssertionError] if [instance] does not extend | ||
/// [AggregateQueryPlatform]. | ||
/// | ||
/// This is used by the app-facing [AggregateQuery] to ensure that | ||
/// the object in which it's going to delegate calls has been | ||
/// constructed properly. | ||
static void verifyExtends(AggregateQueryPlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
} | ||
|
||
final QueryPlatform query; | ||
|
||
Future<AggregateQuerySnapshotPlatform> get({required AggregateSource source}) async { | ||
throw UnimplementedError('get() is not implemented'); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...orm_interface/lib/src/platform_interface/platform_interface_aggregate_query_snapshot.dart
This file contains hidden or 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,21 @@ | ||
import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
|
||
class AggregateQuerySnapshotPlatform extends PlatformInterface { | ||
AggregateQuerySnapshotPlatform({required count}) : _count = count, super(token: _token); | ||
|
||
static final Object _token = Object(); | ||
|
||
/// Throws an [AssertionError] if [instance] does not extend | ||
/// [AggregateQuerySnapshotPlatform]. | ||
/// | ||
/// This is used by the app-facing [AggregateQuerySnapshot] to ensure that | ||
/// the object in which it's going to delegate calls has been | ||
/// constructed properly. | ||
static void verifyExtends(AggregateQuerySnapshotPlatform instance) { | ||
PlatformInterface.verifyToken(instance, _token); | ||
} | ||
|
||
final int _count; | ||
|
||
int get count => _count; | ||
} |
This file contains hidden or 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 hidden or 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
31 changes: 31 additions & 0 deletions
31
packages/cloud_firestore/cloud_firestore_web/lib/src/aggregate_query_web.dart
This file contains hidden or 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,31 @@ | ||
// ignore_for_file: require_trailing_commas | ||
// Copyright 2017, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'package:cloud_firestore_platform_interface/cloud_firestore_platform_interface.dart'; | ||
|
||
import 'interop/firestore.dart' as firestore_interop; | ||
|
||
/// Web implementation for Firestore [AggregateQueryPlatform]. | ||
class AggregateQueryWeb extends AggregateQueryPlatform { | ||
/// instance of Firestore from the web plugin | ||
// final firestore_interop.Firestore firestoreWeb; | ||
|
||
/// instance of DocumentReference from the web plugin | ||
final firestore_interop.AggregateQuery _delegate; | ||
final firestore_interop.Query _webQuery; | ||
|
||
/// Creates an instance of [DocumentReferenceWeb] which represents path | ||
/// at [pathComponents] and uses implementation of [firestoreWeb] | ||
AggregateQueryWeb( | ||
QueryPlatform query, this._webQuery): _delegate = firestore_interop.AggregateQuery(_webQuery), super(query); | ||
|
||
@override | ||
Future<AggregateQuerySnapshotPlatform> get({required AggregateSource source}) async { | ||
// There isn't a source option on web | ||
firestore_interop.AggregateQuerySnapshot snapshot = await _delegate.get(); | ||
|
||
return AggregateQuerySnapshotPlatform(count: snapshot.count); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.