Skip to content

Commit 778b6bc

Browse files
authored
Merge pull request #8 from firebase/new_queries
New queries (and updates to config to use newer Android Studio)
2 parents 7c90133 + 0bd63e5 commit 778b6bc

File tree

11 files changed

+639
-247
lines changed

11 files changed

+639
-247
lines changed

.github/workflows/firestore-android.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Checkout
1515
uses: actions/checkout@master
1616
- name: Download C++ SDK
17-
run: curl -o firestore/android/binary/firebase-cpp-sdk.zip https://dl.google.com/firebase/sdk/cpp/firebase_cpp_sdk_8.5.0.zip --create-dirs
17+
run: curl -o firestore/android/binary/firebase-cpp-sdk.zip https://dl.google.com/firebase/sdk/cpp/firebase_cpp_sdk_11.0.0.zip --create-dirs
1818
- name: Extract SDK
1919
run: unzip firestore/android/binary/firebase-cpp-sdk.zip -d firestore/android/binary
2020
- name: set up JDK 1.8

.github/workflows/firestore-ios.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Checkout
2121
uses: actions/checkout@master
2222
- name: Download C++ SDK
23-
run: curl -o firestore/ios/binary/firebase-cpp-sdk.zip https://dl.google.com/firebase/sdk/cpp/firebase_cpp_sdk_8.5.0.zip --create-dirs
23+
run: curl -o firestore/ios/binary/firebase-cpp-sdk.zip https://dl.google.com/firebase/sdk/cpp/firebase_cpp_sdk_11.0.0.zip --create-dirs
2424
- name: Extract SDK
2525
run: unzip firestore/ios/binary/firebase-cpp-sdk.zip -d firestore/ios/binary
2626
- name: Build

firestore/android/FirestoreSnippetsCpp/app/build.gradle

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ apply plugin: 'com.google.gms.google-services'
99
def firebase_cpp_sdk_dir = "${project.projectDir}/../../binary/firebase_cpp_sdk"
1010

1111
android {
12-
compileSdkVersion 29
12+
compileSdkVersion 31
1313
buildToolsVersion "30.0.2"
1414
compileOptions {
1515
sourceCompatibility JavaVersion.VERSION_1_8
1616
targetCompatibility JavaVersion.VERSION_1_8
1717
}
1818
defaultConfig {
1919
applicationId "com.firebase.firestoresnippetscpp"
20-
minSdkVersion 16
21-
targetSdkVersion 29
20+
minSdkVersion 20
21+
targetSdkVersion 31
2222
multiDexEnabled true
2323
versionCode 1
2424
versionName "1.0"

firestore/android/FirestoreSnippetsCpp/app/src/main/AndroidManifest.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
android:supportsRtl="true"
1111
android:theme="@style/AppTheme"
1212
android:name="androidx.multidex.MultiDexApplication">
13-
<activity android:name=".MainActivity">
13+
<activity android:name=".MainActivity"
14+
android:exported="true">
1415
<intent-filter>
1516
<action android:name="android.intent.action.MAIN" />
1617

firestore/android/FirestoreSnippetsCpp/app/src/main/cpp/snippets.cpp

+82
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,10 @@ void ReadDataQueryOperators(firebase::firestore::Firestore* db) {
856856
FieldValue::String("San Francisco"));
857857
// [END example_filters]
858858

859+
// [START query_filter_not_eq]
860+
cities_ref.WhereNotEqualTo("capital", FieldValue::Boolean(false));
861+
// [END query_filter_not_eq]
862+
859863
}
860864

861865
// https://firebase.google.com/docs/firestore/query-data/queries#array_membership
@@ -918,6 +922,82 @@ void ReadDataArrayContainsAnyOperators(firebase::firestore::Firestore* db) {
918922
// [END cpp_in_filter_with_array]
919923
}
920924

925+
926+
927+
void QueryCollectionGroupFilterEq(firebase::firestore::Firestore* db) // 2 TODO
928+
{
929+
930+
using firebase::firestore::CollectionReference;
931+
using firebase::firestore::FieldValue;
932+
using firebase::firestore::Error;
933+
using firebase::firestore::QuerySnapshot;
934+
using firebase::firestore::DocumentSnapshot;
935+
using firebase::firestore::Query;
936+
937+
// [START query_collection_group_filter_eq]
938+
db->CollectionGroup("landmarks")
939+
.WhereEqualTo("type", FieldValue::String("museum")).Get()
940+
.OnCompletion([](const firebase::Future<QuerySnapshot>& future) {
941+
if (future.error() == Error::kErrorOk) {
942+
for (const DocumentSnapshot& document : future.result()->documents()) {
943+
std::cout << document << std::endl;
944+
}
945+
} else {
946+
std::cout << "Error getting documents: " << future.error_message()
947+
<< std::endl;
948+
}
949+
});
950+
// [END query_collection_group_filter_eq]
951+
952+
}
953+
954+
955+
void QueryCollectionGroupDataset(firebase::firestore::Firestore* db)
956+
{
957+
using firebase::Future;
958+
using firebase::firestore::DocumentReference;
959+
using firebase::firestore::DocumentSnapshot;
960+
using firebase::firestore::Error;
961+
using firebase::firestore::FieldValue;
962+
using firebase::firestore::QuerySnapshot;
963+
using firebase::firestore::WriteBatch;
964+
965+
// [START query_collection_group_dataset]
966+
// Get a new write batch
967+
WriteBatch batch = db->batch();
968+
969+
DocumentReference sf_ref = db->Collection("cities").Document("SF");
970+
batch.Set(sf_ref,{{"name", FieldValue::String("Golden Gate Bridge")}, {"type", FieldValue::String("bridge")}});
971+
batch.Set(sf_ref,{{"name", FieldValue::String("Legion of Honor")}, {"type", FieldValue::String("museum")}});
972+
973+
DocumentReference la_ref = db->Collection("cities").Document("LA");
974+
batch.Set(la_ref,{{"name", FieldValue::String("Griffith Park")}, {"type", FieldValue::String("park")}});
975+
batch.Set(la_ref,{{"name", FieldValue::String("The Getty")}, {"type", FieldValue::String("museum")}});
976+
977+
DocumentReference dc_ref = db->Collection("cities").Document("DC");
978+
batch.Set(dc_ref,{{"name", FieldValue::String("Lincoln Memorial")}, {"type", FieldValue::String("memorial")}});
979+
batch.Set(dc_ref,{{"name", FieldValue::String("National Air and Space Museum")}, {"type", FieldValue::String("museum")}});
980+
981+
DocumentReference tok_ref = db->Collection("cities").Document("TOK");
982+
batch.Set(tok_ref,{{"name", FieldValue::String("Ueno Park")}, {"type", FieldValue::String("park")}});
983+
batch.Set(tok_ref,{{"name", FieldValue::String("National Museum of Nature and Science")}, {"type", FieldValue::String("museum")}});
984+
985+
DocumentReference bj_ref = db->Collection("cities").Document("BJ");
986+
batch.Set(bj_ref,{{"name", FieldValue::String("Jingshan Park")}, {"type", FieldValue::String("park")}});
987+
batch.Set(bj_ref,{{"name", FieldValue::String("Beijing Ancient Observatory")}, {"type", FieldValue::String("museum")}});
988+
989+
// Commit the batch
990+
batch.Commit().OnCompletion([](const Future<void>& future) {
991+
if (future.error() == Error::kErrorOk) {
992+
std::cout << "Write batch success!" << std::endl;
993+
} else {
994+
std::cout << "Write batch failure: " << future.error_message() << std::endl;
995+
}
996+
});
997+
// [END query_collection_group_dataset]
998+
}
999+
1000+
9211001
// https://firebase.google.com/docs/firestore/query-data/queries#compound_queries
9221002
void ReadDataCompoundQueries(firebase::firestore::Firestore* db) {
9231003
using firebase::firestore::CollectionReference;
@@ -1205,6 +1285,8 @@ void RunAllSnippets(firebase::firestore::Firestore* db) {
12051285
snippets::ReadDataExecuteQuery(db);
12061286
snippets::ReadDataQueryOperators(db);
12071287
snippets::ReadDataCompoundQueries(db);
1288+
snippets::QueryCollectionGroupDataset(db);
1289+
snippets::QueryCollectionGroupFilterEq(db);
12081290

12091291
snippets::ReadDataOrderAndLimitData(db);
12101292

firestore/android/FirestoreSnippetsCpp/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.50'
4+
ext.kotlin_version = '1.7.10'
55
repositories {
66
google()
77
mavenCentral()

firestore/android/FirestoreSnippetsCpp/gradle.properties

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ android.enableJetifier=true
2121
kotlin.code.style=official
2222
# Firebase cpp SDK location
2323
systemProp.firebase_cpp_sdk.dir=../binary/firebase_cpp_sdk
24+
25+
26+
org.gradle.warning.mode=all
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Mon Feb 03 15:00:49 PST 2020
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip

firestore/ios/Podfile

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
platform :ios, '11.0'
22

33
target 'firestore-snippets-cpp' do
4-
use_frameworks!
4+
use_frameworks! :linkage => :static
55

6-
pod 'Firebase/Auth', '8.7.0'
7-
pod 'Firebase/Firestore', '8.7.0'
6+
pod 'Firebase/Auth', '10.9.0'
7+
pod 'Firebase/Firestore', '10.9.0'
88

99
end
10+
11+
post_install do |installer|
12+
installer.pods_project.targets.each do |target|
13+
target.build_configurations.each do |config|
14+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)