Skip to content

Commit fd13db5

Browse files
authored
Multi DB API (#164)
* Multi DB API * Updated changelog
1 parent 746cf13 commit fd13db5

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
- [added] `firebase.App` now provides a new `DatabaseWithURL()` function
4+
for initializing a database client from a URL.
5+
36
# v3.3.0
47

58
- [fixed] Fixing a regression introduced in 3.2.0, where `VerifyIDToken()`

firebase.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,18 @@ func (a *App) Auth(ctx context.Context) (*auth.Client, error) {
7979
return auth.NewClient(ctx, conf)
8080
}
8181

82-
// Database returns an instance of db.Client.
82+
// Database returns an instance of db.Client to interact with the default Firebase Database
83+
// configured via Config.DatabaseURL.
8384
func (a *App) Database(ctx context.Context) (*db.Client, error) {
85+
return a.DatabaseWithURL(ctx, a.dbURL)
86+
}
87+
88+
// DatabaseWithURL returns an instance of db.Client to interact with the Firebase Database
89+
// identified by the given URL.
90+
func (a *App) DatabaseWithURL(ctx context.Context, url string) (*db.Client, error) {
8491
conf := &internal.DatabaseConfig{
8592
AuthOverride: a.authOverride,
86-
URL: a.dbURL,
93+
URL: url,
8794
Opts: a.opts,
8895
Version: Version,
8996
}

firebase_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ func TestDatabase(t *testing.T) {
246246
if c, err := app.Database(ctx); c == nil || err != nil {
247247
t.Errorf("Database() = (%v, %v); want (db, nil)", c, err)
248248
}
249+
url := "https://other-mock-db.firebaseio.com"
250+
if c, err := app.DatabaseWithURL(ctx, url); c == nil || err != nil {
251+
t.Errorf("Database() = (%v, %v); want (db, nil)", c, err)
252+
}
249253
}
250254

251255
func TestDatabaseAuthOverrides(t *testing.T) {

0 commit comments

Comments
 (0)