MelatoninGummies
MelatoninGummies

Reputation: 25

How to connect Swift to a postgresql database hosted on Google Cloud

I'm new to working with back-end, but have been running into issues trying to get my iOS app to connect to my PostgreSQL DB.

I have developed an app with Swift which is a game that I want to run locally on iOS devices. I have a PostgreSQL DB set up in Google Cloud Platform but I cannot figure out how to get the Swift app to connect to my PostgreSQL DB.

I've read some about using Vapor or Perfect to run the application using Googles App Engine but I'm not sure that is what I want to do since I want the app to run locally but there are a few aspects of my app that I need a global database for.

Would anyone be able to point me in the right direction of how I need to connect my Swift application with Google Cloud's PostgreSQL?

Upvotes: 0

Views: 1746

Answers (2)

kurtisvg
kurtisvg

Reputation: 3565

Your question is pretty much very similar to this one.

In short, the correct answer is you shouldn't connect your client side application directly to the database. Instead, you should build a service that can connect to the database, and act as a service between your application. This helps prevent any unauthorized queries to your database and provides better performance. If you wanted to do this on GCP, you could look into something like Google Cloud Functions or Google Cloud App Engine to act as a service.

An alternative would be to use a "Database-as-a-Service" like Cloud Firestore. This is a scalable, pay-as-you-go service with great mobile support.

Upvotes: 1

Kingsley Mitchell
Kingsley Mitchell

Reputation: 2589

Yeah sure you need a server, ruby on rails to connect to your Postgres database.

The server will facilitate data back and forth from the Google cloud Postgressql

Upvotes: 0

Related Questions