Skip to content

Commit 9099f7f

Browse files
authored
Expose MultiDb API (#11365)
* Expose MultiDb API * Changelog for MultiDb * Expose MultiDB API * Pretty * Add preview comment
1 parent b1d5038 commit 9099f7f

File tree

4 files changed

+54
-49
lines changed

4 files changed

+54
-49
lines changed

Firestore/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Unreleased
2+
- [feature] Expose MultiDb API for public preview. (#10465)
23
- [fixed] Fixed a compilation warning related to integer casting. (#11332)
34

45
# 10.9.0

Firestore/Source/API/FIRFirestore+Internal.h

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,6 @@ NS_ASSUME_NONNULL_BEGIN
8383
@property(nonatomic, assign, readonly) const model::DatabaseId &databaseID;
8484
@property(nonatomic, strong, readonly) FSTUserDataReader *dataReader;
8585

86-
/**
87-
* Creates, caches, and returns named `Firestore` object for the specified `FirebaseApp`. Each
88-
* subsequent invocation returns the same `Firestore` object.
89-
*
90-
* @param app The `FirebaseApp` instance to use for authentication and as a source of the Google
91-
* Cloud Project ID for your Firestore Database. If you want the default instance, you should
92-
* explicitly set it to `FirebaseApp.app()`.
93-
* @param database The database name.
94-
*
95-
* @return The named `Firestore` instance.
96-
*/
97-
+ (instancetype)firestoreForApp:(FIRApp *)app
98-
database:(NSString *)database NS_SWIFT_NAME(firestore(app:database:));
99-
100-
/**
101-
* Creates, caches, and returns named `Firestore` object for the default _app_. Each subsequent
102-
* invocation returns the same `Firestore` object.
103-
*
104-
* @param database The database name.
105-
*
106-
* @return The named `Firestore` instance.
107-
*/
108-
+ (instancetype)firestoreForDatabase:(NSString *)database NS_SWIFT_NAME(firestore(database:));
109-
11086
@end
11187

11288
NS_ASSUME_NONNULL_END

Firestore/Source/API/FIRFirestore.mm

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,31 @@ - (instancetype)initWithDatabaseID:(model::DatabaseId)databaseID
166166
return self;
167167
}
168168

169+
+ (instancetype)firestoreForApp:(FIRApp *)app database:(NSString *)database {
170+
if (!app) {
171+
ThrowInvalidArgument("FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like "
172+
"to use the default FirebaseApp instance.");
173+
}
174+
if (!database) {
175+
ThrowInvalidArgument("Database identifier may not be nil. Use '%s' if you want the default "
176+
"database",
177+
DatabaseId::kDefault);
178+
}
179+
180+
id<FSTFirestoreMultiDBProvider> provider =
181+
FIR_COMPONENT(FSTFirestoreMultiDBProvider, app.container);
182+
return [provider firestoreForDatabase:database];
183+
}
184+
185+
+ (instancetype)firestoreForDatabase:(NSString *)database {
186+
FIRApp *app = [FIRApp defaultApp];
187+
if (!app) {
188+
ThrowIllegalState("Failed to get FirebaseApp instance. Please call FirebaseApp.configure() "
189+
"before using Firestore");
190+
}
191+
return [self firestoreForApp:app database:database];
192+
}
193+
169194
- (FIRFirestoreSettings *)settings {
170195
// Disallow mutation of our internal settings
171196
return [_settings copy];
@@ -512,31 +537,6 @@ @implementation FIRFirestore (Internal)
512537
return _firestore->database_id();
513538
}
514539

515-
+ (instancetype)firestoreForApp:(FIRApp *)app database:(NSString *)database {
516-
if (!app) {
517-
ThrowInvalidArgument("FirebaseApp instance may not be nil. Use FirebaseApp.app() if you'd like "
518-
"to use the default FirebaseApp instance.");
519-
}
520-
if (!database) {
521-
ThrowInvalidArgument("Database identifier may not be nil. Use '%s' if you want the default "
522-
"database",
523-
DatabaseId::kDefault);
524-
}
525-
526-
id<FSTFirestoreMultiDBProvider> provider =
527-
FIR_COMPONENT(FSTFirestoreMultiDBProvider, app.container);
528-
return [provider firestoreForDatabase:database];
529-
}
530-
531-
+ (instancetype)firestoreForDatabase:(NSString *)database {
532-
FIRApp *app = [FIRApp defaultApp];
533-
if (!app) {
534-
ThrowIllegalState("Failed to get FirebaseApp instance. Please call FirebaseApp.configure() "
535-
"before using Firestore");
536-
}
537-
return [self firestoreForApp:app database:database];
538-
}
539-
540540
+ (FIRFirestore *)recoverFromFirestore:(std::shared_ptr<Firestore>)firestore {
541541
return (__bridge FIRFirestore *)firestore->extension();
542542
}

Firestore/Source/Public/FirebaseFirestore/FIRFirestore.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ NS_SWIFT_NAME(Firestore)
6262
*/
6363
+ (instancetype)firestoreForApp:(FIRApp *)app NS_SWIFT_NAME(firestore(app:));
6464

65+
/**
66+
* This method is in preview. API signature and functionality are subject to change.
67+
*
68+
* Creates, caches, and returns named `Firestore` object for the specified `FirebaseApp`. Each
69+
* subsequent invocation returns the same `Firestore` object.
70+
*
71+
* @param app The `FirebaseApp` instance to use for authentication and as a source of the Google
72+
* Cloud Project ID for your Firestore Database. If you want the default instance, you should
73+
* explicitly set it to `FirebaseApp.app()`.
74+
* @param database The database name.
75+
*
76+
* @return The named `Firestore` instance.
77+
*/
78+
+ (instancetype)firestoreForApp:(FIRApp *)app
79+
database:(NSString *)database NS_SWIFT_NAME(firestore(app:database:));
80+
81+
/**
82+
* This method is in preview. API signature and functionality are subject to change.
83+
*
84+
* Creates, caches, and returns named `Firestore` object for the default _app_. Each subsequent
85+
* invocation returns the same `Firestore` object.
86+
*
87+
* @param database The database name.
88+
*
89+
* @return The named `Firestore` instance.
90+
*/
91+
+ (instancetype)firestoreForDatabase:(NSString *)database NS_SWIFT_NAME(firestore(database:));
92+
6593
/**
6694
* Custom settings used to configure this `Firestore` object.
6795
*/

0 commit comments

Comments
 (0)