This is a sample app for the preview version of Firebase DataConnect. This service is currently in Private Preview at no cost for a limited time. Sign up for the program at Firebase Data Connect. This quickstart will not work if you don't have access to the preview.
Follow these steps to get up and running with Firebase DataConnect. For more detailed instructions, check out the official documentation.
- Open Firebase Data Connect in your Firebase Console project and select Get Started.
- Create a new Data Connect service and a Cloud SQL instance. Ensure the Blaze plan is active. Find pricing details at Firebase Pricing.
- Choose your server region. If you plan to use vector search, select
us-central1. - Wait for the Cloud SQL instance to be provisioned. Once it's ready, you can manage it in the Cloud Console.
Ensure the Firebase CLI is installed and up to date:
npm install -g firebase-toolsThis repository contains the quickstart to help you explore the functionalities of DataConnect.
-
Clone this repository to your local machine.
-
Navigate to the
dataconnectfolder and initialize your Firebase project:cd ./dataconnect(Optional): If you plan to use other Firebase features, run
firebase initinstead, and select both DataConnect options as well as any additional feature you want to use.
- Install VS Code.
- Download and install the Firebase DataConnect extension.
- Open this quickstart in VS Code and log in to your Firebase account using the Firebase extension.
- In the Firebase DataConnect VSCode extension, click Start Emulators and confirm that the emulators are running in the terminal.
- In VS Code, open
dataconnect/movie_insert.gql. Ensure the emulators in the Firebase DataConnect extension are running. - You should see a Run (local) button at the top of the file. Click this to insert mock movie data into your database.
- Check the DataConnect Execution terminal to confirm that the data was added successfully.
-
Navigate to the
appfolder and install dependencies:cd ./app npm install -
Start the app:
npm run dev
-
Create a Web App in the Firebase Console and take note of your App ID.
-
In the Firebase Console, click on Add App. You can ignore the SDK setup for now, but note the generated
firebaseConfigobject. -
Replace the
firebaseConfiginapp/src/lib/firebase.tsx:const firebaseConfig = { apiKey: "API_KEY", authDomain: "PROJECT_ID.firebaseapp.com", projectId: "PROJECT_ID", storageBucket: "PROJECT_ID.appspot.com", messagingSenderId: "SENDER_ID", appId: "APP_ID" };
-
Build the web app for hosting deployment:
cd ./app npm run build -
Set up Firebase Authentication with Google Sign-In. Optionally, allow domains for Firebase Auth in your project console (e.g.,
http://127.0.0.1). -
Allow domains for Firebase Auth in your project console (e.g.,
http://127.0.0.1). -
In
dataconnect/dataconnect.yaml, ensure that yourinstanceId,database, andserviceIdmatch your project configuration:specVersion: "v1alpha" serviceId: "your-service-id" location: "us-central1" schema: source: "./schema" datasource: postgresql: database: "your-database-id" cloudSql: instanceId: "your-instance-id" connectorDirs: ["./movie-connector"]
-
Deploy your project:
npm install -g firebase-tools firebase login --reauth firebase use --add firebase deploy --only dataconnect,hosting
-
To compare schema changes, run:
firebase dataconnect:sql:diff
-
If the changes are acceptable, apply them with:
firebase dataconnect:sql:migrate
© Google, 2024. Licensed under an Apache-2 license.