Deploying Firebase Functions onWrite realtime with two different databases [duplicate] - firebase-realtime-database

This question already has an answer here:
How do I setup firebase realtime DB triggers for multiple databases using cloud functions?
(1 answer)
Closed 1 year ago.
I've two apps, same logic, but differents database.
On app 1, I use database-1, for app 2, I use database-2.
On my first app, I've deployed a onWrite functions, that's works well. The function is trigged and everything works well.
Now I want to deploy the same function, on the same project but with different database, it's that possible?

functions.database.instance('database-2').ref('/foo/bar')
According to docs, you can specify a Realtime Database instance with instance('INSTANCE_NAME').

Related

How to connect an iOS app to an existing database

I'm about to make an iOS app for a company that will need to access an already existing database table on SQL Server. All I want to do is make a connection to the already existing database table and compare it to a data item within the app - but I cant figure out how to create this connection using Objective-C. All of the information I've found deals with making a database yourself using sqlite and then importing the table data into the sqlLite database, but I've already got a live database on SQLServer I need to connect to.
this question: ios app: How to efficiently use an existing database was very similar to mine and had no resolution.
this one is also similar: Xcode connect to the MS SQL database it suggests to use a webservice - but I'm using Objective-c - will there be an issue getting my Objective-c code to communicate with the webservice?
I'd really like to do it without a webservice but it doesn't seem like an option.
I keep reading about RESTFULapi's but there is absolutely no documentation that I can found that will explain how to perform anything similar to what I'm talking about (feel free to point me to the resource if you disagree)
Any recommendations would be appreciated

When should I use firebase's realtime database? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to make use of Firebase's services such as authentication and the real-time database. It makes integrating with the front-end clients very easy. However, I am struggling with the database portion. I still want a relational database, so I can more easily interact with my other data, so I thought of Rails and Postgres for this. I know Rails has ActionCable, but I want to utilize more of the services in firebase. I wanted to have my frontend clients talk to my Rails app and then have the Rails save to Postgres then transforming the data in a suitable NoSQL format for Firebase's DB. Is this a proper way of using Firebase? How else can I utilize Firebase's real-time DB without making it the source of truth?
I think you can do it. I usually do things like that using an event source architecture.
Let's say I have a class called User and I want to keep them in sync with a user collection on firebase. For that purpose, I would put a listener on User:
models/user_observer.rb
class UserObserver < ActiveRecord::Observer
include Wisper::Publisher
def initialize
subscribe(FirebaseUserPublisher, async: true)
super
end
def after_save(user)
publish_changes_to_firebase(user)
end
end
so that, every time a user is changed/created, the changes will be async reflected on your firebase and the FirebaseUserPublisher class will take care of it.
Remember that this means eventual consistency: if the FirebaseUserPublisher fails, your data is out of sync
This is basically what we are doing in a large collaborative web-application. We have a Java-based backend which watches specific keys in our Firebase RTDB for changes/additions/deletions, and responds accordingly. It uses the data from Firebase and then fires up a new Apache Mesos executor for each workspace that is currently active in our web-application (Has "presence"), with each instance having its own PostgreSQL database that the executor uses. This database is populated using data scattered around our RTDB.
When we want to have the backend perform a long-running calculation or task for the client, we write some data to a specific location ("dbRequests") outlining the task we want and some user-defined parameters. The backend executor reads the request and then goes off and spawns a worker service to execute the task for us. Once that is done, it writes new data as a child to the original request which the client picks-up and displays to the user (Or, in the case of reports, opens a new tab with the rendered charts using the calculated data). Generally, it works well for our use-case: many connected users working in a digital workspace with live updates for each connected client.
The biggest problem we've faced using this model is running data migration scripts, and managing all of the data we have in the RTDB. To be expected I suppose, since it's essentially a giant JSON-structure ;).

Sharing database between multiple swift apps

I need to be able to have 3 swift apps which can communicate with each other. Think of app 1 as a base app which communicates with a server and stores info in a local DB and app 2 and 3 need to read (and POSSIBLY write) to that DB created in app 1.
Looking on the net, this appears to be possible with 'app groups'.If all 3 apps are under the same app group, will they automatically have a 'shared folder' where I can create and/or store a Realm DB? Would app 2 and 3 use NSFileManager then to interact with this shared file? I can't seem to find any examples of this in action.
You need a central database to read and write to, from multiple client apps, that is an API at its simplest. In other words, you need an API for your Apps. It is possible that you might be thinking this is more challenging than a shared folder and shared Realm DB but that is not the case, you are actually making the problem more complex by trying to reinvent the wheel of how N number mobile apps share data with each other, it is of no matter that N number apps all reside on the same device, in iOS an app is in a Sandbox, and you trying to circumvent that.
My guess is that your approach to this problem is centered on using Realm DB, but Realm DB is probably not the right tool for the job as Realm DB is a LOCAL database serving ONE app, if Realm DB was designed to work with multiple apps it would be an API tool like Firebase or Amazon S3.
You need to create an API and the API just has one database backing it.
Say for example, App1 needs to save a picture that App2 needs to be able to retrieve and view.
Your API will have a method called:
SavePicture(byte[] picture)
Now App1 saves the picture by calling your API and the picture is saved, either in the database or on the server hard drive, either way there is a record in the database for the saved picture.
Now App2 wants new pictures, say there is a refresh button on App2, the refresh button touch calls your API, another method called
[byte[]] GetPictures()
The GetPictures API method returns an Array of byte[], each being an image, that App2 can display.
You might want to checkout Firebase, this seems to be a third party tool that people use that are not familiar with building APIs, or learn how to build an API, using PHP, Ruby on Rails, ASP.NET Web API, Python, etc. with a database that could be MySQL, PostgreSQL, Sql Server, MongoDB, RavenDB, etc.

Firebase databases replication

I need a data from one Firebase project's database in 2 iOS apps (with different bundle names). So, the question is:
Is it possible to configure replication between 2 different Firebase project's databases? Or is it possible to use 1 Firebase project (1 database) for 2 ios apps?
There is no built-in feature to replicate Firebase Databases.
I'm not aware of any tools that replicate between two Firebase Databases. The closest is probably making a backup from one database and restore to another, but it'll be a parent/child setup.
Yes, multiple iOS apps can talk to the same Firebase Database. Just click to add another app on your project's Firebase Console.

link 2 iPhones for a single iOS app database

I'm developing an app for my summer iPhone class that is designed for couples, and am not sure the best way to have two different users phones reading and writing to the same database for a single account. The two users create and grant points to each other for "rewards", "penalties" and "prizes". I'm attempting to put the local databases into CoreData and then push it into iCloud. However, I'm only finding ways that that works for a single persons app. This is a two player game that needs to update a shared database. I would greatly appreciate if you would have any suggestions on ways to either send notifications directly to each and maintain congruent separate local databases, or to have a single back end database for two users in a single account that both users' phone can push and pull from to read and write. I'm having trouble finding the right path to pursue for this.
Thanks.
You can easily save Database on server side with the help of many mechanism like PHP Script is the best example for this.
link - Advices on server implementation for server/client structure iOS App development?
There is a third-party framework for iOS called Parse. It's a terrific backend service that adds a cloud database. You can create objects and store it in the cloud and access it anytime, and it comes with push notifications and analytics functionality. It's tuned for many platforms, including iOS and it's straightforward to access all of its functionalities.
The site is here: https://parse.com
Whenever you try to use one database for multiple device, you need to create / save database in server side or you can try Parse. because local database is always used for device specific.

Resources