Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 259
Gary Avatar asked Mar 22 '17 20:03

Gary


People also ask

Can Cloud function connect to cloud SQL?

After you configure Cloud Functions, you can connect to your Cloud SQL instance. For public IP paths, Cloud Functions provides encryption and connects using the Cloud SQL Auth proxy through Unix sockets.

How do I use Firebase cloud function?

Implementation path. Install the Firebase CLI and initialize Cloud Functions in your Firebase project. Write JavaScript code (or TypeScript code to transpile at deployment) to handle events from Firebase services, Google Cloud services, or other event providers. Use the local emulator to test your functions.

What platform is used to store data in Firebase?

Firebase Realtime Database is a NoSQL cloud database that is used to store and sync the data. The data from the database can be synced at a time across all the clients such as android, web as well as IOS. The data in the database is stored in the JSON format and it updates in real-time with every connected client.

How do I connect Firebase to Google Cloud?

Add Firebase to your existing Google Cloud project: Log in to the Firebase console, then click Add project. Select your existing Google Cloud project from the dropdown menu, then click Continue. (Optional) Enable Google Analytics for your project, then follow the prompts to select or create a Google Analytics account.


1 Answers

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!

like image 79
Robert-Jan Huijsman Avatar answered Sep 30 '22 04:09

Robert-Jan Huijsman