Can I read data from realtime data base across cloud functions in react native - firebase

I want to read and write data in database real time across cloud functions but I don't know if this is possible, also I don't know if this is good practice or if is better make this through with SDK database realtime
I learning firebase and react native, I am new learning these topics.

From the docs:
Cloud Functions for Firebase lets you automatically run backend code in response to events triggered by Firebase features and HTTPS requests. Your code is stored in Google's cloud and runs in a managed environment. There's no need to manage and scale your own servers.
Cloud Functions runs Node v.6.11.5, so we recommend that you develop locally with this version.
You are able to use realtime database trigggers like onCreate(), onWrite(). Also you are able to use set() to send data to the realtime database.
https://firebase.google.com/docs/functions/
https://firebase.google.com/docs/functions/database-events

Related

Should I make a RESTful API using Cloud Functions or call Firebase and Firestore in app?

I am currently creating a marketplace mobile application from scratch and I'm using React Native for the front-end part and Firebase for the backend (using Firebase and Firestore).
I am wondering wether :
I should create a RESTful API using cloud functions and express to create API endpoints (that would connect to firebase and firestore) that I'd call from my redux actions in my React Native app (using redux thunk).
or, I should call firebase and firestore directly from redux actions.
I see couple pros and cons for each method.
Restful API pros :
Safer as I can check and manipulate submitted data more easily
Custom API reply (I can manipulate the return data)
Restful API cons :
Probably slower as I would have to call an API endpoint that will then call firebase and/or firestore.
Won't be as easy to set listeners on firestore data
What do you think about it ?
Which option should I choose knowing that I predict that the app will get a few thousand users daily. I want it to be as fast and safe as possible and be able to set listeners for notifications purposes.
In my opinion you should mix them, if you have to manage users, products or etc. Firebase produces client and admin sdk that has different roles. If you haven't need manage any data of products or users or etc. you can simply use client sdk.
My advise is you can use admin sdk on API (server-side) and feel free to use client sdk on your clients.
Use as managements on API, listening data, realtime chat etc. via client sdk.
You can check admin and client sdk. Also npm packages for React Native here.
Mixing will be of help, you can try:
Listen for small amounts of data using the client SDK
Write and sort data using the cloud functions
In my experience, writing to a firebase database that uses ordered ids (in my case) leads to some huge problems in the long run. I lost a good chunk of data when my app accidentally wrote to a root index instead of a child index when the app was resumed from inactivity because the android system cleared the RAM.
Also, for notification, use Firebase Cloud Messaging.

Is it possible to deploy Firebase functions outside of Google Cloud?

I'd like to implement a full text search an app that is using Cloud Firestore.
Integrating with Algolia sounds great, but it can't work on the free Spark plan since outbound networking is limited to Google services only.
Therefore, the obvious question:
(1) Is it possible to use firebase-functions to create a function that monitors Firestore changes and deploy it to something like Zeit's Lambda or AWS Lambda?
Somewhat related question:
(2) Is it possible to use onSnapshot instead of onCreate/onUpdate/etc. to monitor Firestore changes?
You can't deploy Cloud Functions code to other serverless function providers. You can certainly try to reuse your core logic, but each provider has its own APIs and infrastructure, and firebase-functions only knows how to work with Cloud Functions.

How can I use Firebase to query an external API and store data in Firestore?

I'm teaching myself to use Flutter and I'm making an app that queries The Movie Database API. Currently, I'm having the client query the API on launch but I'm thinking this is not the most efficient way of doing it, and I would rather have the client query a backend service like Firebase to get the same data.
I would appreciate some guidance into where to start in order to setup a periodical process to query the API and use the results as entries into a Firestore DB. I've looked online but I might be using suboptimal keywords since I haven't found a good tutorial or example for this.
Thanks.
You can use Firebase Cloud Functions to build code that runs on Firebase servers to fill your Firebase database, but you can only make HTTP requests to non-Google addresses if you use a paid plan.
https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html explains how to invoke periodic tasks with Cloud Functions. It utilizes Google AppEngine for that because Cloud Functions doesn't provide that out of the box.

What is the use case of Firebase Queue?

I am doing some experiments on Firebase realtime database. Though I came across firebase-queue. This is what docs says https://github.com/firebase/firebase-queue.
A fault-tolerant, multi-worker, multi-stage job pipeline built on the Firebase Realtime Database.
What does it mean ?
firebase-queue lets you use Realtime Database to submit jobs to a backend server you control. Clients write into the database, and that data is received by firebase-queue, where you can do whatever you want with it.
If you have interest in running backend code that reacts to changes in your Firebase project, you are much better off looking into Cloud Functions for Firebase, because you won't have to manage a backend server at all. You just write and deploy code to it.

How do I use Cloud DataStore or Cloud SQL from Cloud Functions for Firebase?

I'm building a Firebase app, and plan to use the real-time database when I need real-time updates. However, most of the application data is more traditional.
Now that Functions is a thing, how do I also leverage either DataStore or CloudSQL? Can anyone point me to specific documentation or examples how to read/write with either of those services from a function?
Neither Cloud Datastore nor Cloud SQL support Cloud Functions yet, which means you aren't yet able to trigger Cloud Functions based on their events the way you can with the Firebase Realtime Database.
Fortunately, once a Cloud Function has been triggered (for example via HTTP), you can still read and write from Datastore and SQL as you would from any other Node.js code. Here is documentation for Cloud Datastore, and here it is for Cloud SQL.
Finally, if you're adventurous and might like to provide early feedback on upcoming integrations like Datastore, fill out this form!

Resources