Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1167bb4

Browse files
Firebase Realtime DB and Firestore in the same app #553
1 parent a82d088 commit 1167bb4

File tree

11 files changed

+66
-20
lines changed

11 files changed

+66
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
[Firebase Android SDK Changelog](https://firebase.google.com/support/release-notes/android)
55

66

7-
## 5.0.0 (work in progress)
7+
## 5.0.1 (2017, November 28)
8+
9+
### New
10+
- [#553](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/553) Firebase Realtime DB and Firestore in the same app
11+
12+
13+
## 5.0.0 (2017, November 28)
814

915
### New
1016
- [#507](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/issues/507) Firestore anytime soon?

demo-ng/app/item/items.component.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
<ScrollView>
55
<StackLayout class="page">
66
<Label text="After pressing those buttons, check the console log" textWrap="true"></Label>
7+
78
<Label text="Authentication" class="h2"></Label>
89
<Button text="login anonymously" (tap)="loginAnonymously()" class="button button-user"></Button>
10+
11+
<Label text="Realtime DB" class="h2"></Label>
12+
<Button text="Get companies" (tap)="doWebGetValueForCompanies()" class="button"></Button>
13+
914
<Label text="Firestore" class="h2"></Label>
1015
<Button text="Add" (tap)="firestoreAdd()" class="button"></Button>
1116
<Button text="Set" (tap)="firestoreSet()" class="button"></Button>

demo-ng/app/item/items.component.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Component, OnInit } from "@angular/core";
22
import { firestore } from "nativescript-plugin-firebase";
33
const firebase = require("nativescript-plugin-firebase/app");
4+
const firebaseWebApi = require("nativescript-plugin-firebase/app");
45

56
@Component({
67
selector: "ns-items",
@@ -203,4 +204,14 @@ export class ItemsComponent implements OnInit {
203204
})
204205
.catch(err => console.log("Delete failed, error" + err));
205206
}
207+
208+
public doWebGetValueForCompanies(): void {
209+
const path = "/companies";
210+
firebaseWebApi.database().ref(path)
211+
.once("value")
212+
.then(result => {
213+
console.log(`${result.key} => ${JSON.stringify(result.val())}`);
214+
})
215+
.catch(error => console.log("doWebGetValueForCompanies error: " + error));
216+
}
206217
}

docs/DATABASE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ If you can spare 41 seconds, check (an older version of) this plugin's [demo app
44
[![YouTube demo, 41 sec](images/yt-thumb-database.png)](https://youtu.be/7zYU5e0Djkw "YouTube demo, 41 sec")
55

66
## Enabling the database features
7-
*Only* if you choose to use **Firestore** (instead of the default DB) these features won't be available.
7+
Before plugin version 5.0.0 this was enabled by default, but since 5.0.0 we're also supporting Firestore.
8+
9+
If your saved config file `firebase.nativescript.json` (in the root of your project) doesn't include `"realtimedb"` we'll assume `true` for backward compatibility.
10+
You can disable it by editing that file and setting `"realtimedb": false`. Then run `rm -rf platforms && rm -rf node_modules && npm i`.
811

912
## Functions
1013

docs/FIRESTORE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/firestore.png" height="85px" alt="Cloud Firestore"/>
22

33
## Enabling Firestore
4-
During plugin installation you'll be prompted to use either Firestore or the default DB.
4+
During plugin installation you'll be asked whether or not you use Firestore.
55

66
In case you're upgrading and you have the `firebase.nativescript.json` file in your project root, edit it and add: `"firestore": true`.
77
Then run `rm -rf platforms && rm -rf node_modules && npm i`.

publish/scripts/installer.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,11 @@ function askAndroidPromptResult(result) {
129129
function promptQuestions() {
130130
prompt.get([{
131131
name: 'firestore',
132-
description: 'Are you using Cloud Firestore instead of the regular Database engine (y/n)',
132+
description: 'Are you using Cloud Firestore (y/n)',
133+
default: 'n'
134+
}, {
135+
name: 'realtimedb',
136+
description: 'Are you using Realtime DB (y/n)',
133137
default: 'n'
134138
}, {
135139
name: 'remote_config',
@@ -222,8 +226,8 @@ function writePodFile(result) {
222226
`pod 'Firebase', '~> 4.6.0'
223227
pod 'Firebase/Auth'
224228
225-
# Uncomment if you want to enable the regular Database (instead of Cloud Firestore)
226-
` + (!isSelected(result.firestore) ? `` : `#`) + `pod 'Firebase/Database'
229+
# Uncomment if you want to enable Realtime DB
230+
` + (!isPresent(result.realtimedb) || isSelected(result.realtimedb) ? `` : `#`) + `pod 'Firebase/Database'
227231
228232
# Uncomment if you want to enable Cloud Firestore
229233
` + (isSelected(result.firestore) ? `` : `#`) + `pod 'Firebase/Firestore'
@@ -309,8 +313,8 @@ dependencies {
309313
def googlePlayServicesVersion = project.hasProperty('googlePlayServicesVersion') ? project.googlePlayServicesVersion : firebaseVersion
310314
compile "com.google.android.gms:play-services-base:$googlePlayServicesVersion"
311315
312-
// Uncomment if you want to use the regular Database (instead of 'Cloud Firestore')
313-
` + (!isSelected(result.firestore) ? `` : `//`) + ` compile "com.google.firebase:firebase-database:$firebaseVersion"
316+
// Uncomment if you want to use the regular Database
317+
` + (!isPresent(result.realtimedb) || isSelected(result.realtimedb) ? `` : `//`) + ` compile "com.google.firebase:firebase-database:$firebaseVersion"
314318
315319
// Uncomment if you want to use 'Cloud Firestore'
316320
` + (isSelected(result.firestore) ? `` : `//`) + ` compile "com.google.firebase:firebase-firestore:$firebaseVersion"
@@ -454,3 +458,7 @@ module.exports = function() {
454458
function isSelected(value) {
455459
return value === true || (typeof value === "string" && value.toLowerCase() === 'y');
456460
}
461+
462+
function isPresent(value) {
463+
return value !== undefined;
464+
}

src/.npmignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44
tsconfig.json
55
references.d.ts
66
platforms/android/libraryproject/
7-
platforms/ios/typings/
7+
platforms/ios/typings/
8+
platforms/android/typings/
9+
platforms/web

src/firebase.android.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ firebase.init = arg => {
200200

201201
arg = arg || {};
202202

203-
if (typeof(com.google.firebase.firestore) === "undefined") {
203+
if (typeof(com.google.firebase.database) !== "undefined") {
204204
firebase.ServerValue = {
205205
TIMESTAMP: firebase.toJsObject(com.google.firebase.database.ServerValue.TIMESTAMP)
206206
};
@@ -210,7 +210,9 @@ firebase.init = arg => {
210210
fDatabase.getInstance().setPersistenceEnabled(true);
211211
}
212212
firebase.instance = fDatabase.getInstance().getReference();
213-
} else {
213+
}
214+
215+
if (typeof(com.google.firebase.firestore) !== "undefined") {
214216
// Firestore has offline persistence enabled by default
215217
if (!arg.persist) {
216218
com.google.firebase.firestore.FirebaseFirestore.getInstance().setFirestoreSettings(

src/firebase.ios.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ firebase.init = arg => {
613613
}
614614

615615
try {
616-
// this is only available when the Database Pod is loaded (not with Firestore)
616+
// this is only available when the Realtime DB Pod is loaded
617617
if (typeof(FIRServerValue) !== "undefined") {
618618
firebase.ServerValue = {
619619
TIMESTAMP: FIRServerValue.timestamp()
@@ -636,9 +636,10 @@ firebase.init = arg => {
636636
if (arg.persist) {
637637
FIRDatabase.database().persistenceEnabled = true;
638638
}
639-
640639
firebase.instance = FIRDatabase.database().reference();
641-
} else if (typeof(FIRStorage) !== "undefined") {
640+
}
641+
642+
if (typeof(FIRStorage) !== "undefined") {
642643
// Firestore has offline persistence enabled by default
643644
if (arg.persist === false) {
644645
const fIRFirestoreSettings = FIRFirestoreSettings.new();

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-plugin-firebase",
3-
"version": "5.0.0",
3+
"version": "5.0.1",
44
"description": "Fire. Base. Firebase!",
55
"main": "firebase",
66
"typings": "index.d.ts",

0 commit comments

Comments
 (0)