|
| 1 | +--- |
| 2 | +title: Firestore |
| 3 | +description: Explains how to integrate Firebase Firestore |
| 4 | +sidebar: |
| 5 | + order: 2 |
| 6 | +--- |
| 7 | + |
| 8 | +import { Steps } from '@astrojs/starlight/components'; |
| 9 | + |
| 10 | +# Firestore Integration in ComposeFlow |
| 11 | + |
| 12 | +Firestore integration in ComposeFlow allows you to seamlessly manage and interact with your Firestore database within your ComposeFlow projects. This guide will walk you through setting up and using Firestore in ComposeFlow. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +:::note |
| 17 | +### Prerequisites |
| 18 | + |
| 19 | +Before you begin, ensure that Firebase integration is properly configured for your project. For detailed instructions, refer to the [Firebase Setup Guide](/firebase/setup). |
| 20 | +::: |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Using Firestore in ComposeFlow |
| 25 | + |
| 26 | +### 1. Associating a Data Type with a Firestore Collection |
| 27 | + |
| 28 | +<Steps> |
| 29 | +1. Navigate to the **Firestore** section in the top-level navigation of ComposeFlow. This is your entry point for managing Firestore collections and their associations with data types. |
| 30 | + |
| 31 | +2. **Tap the "Associate a Data Type" Button** |
| 32 | + This button allows you to associate a Firestore collection with a specific data type in ComposeFlow. |
| 33 | +  |
| 34 | + |
| 35 | +3. **Fill in the Association Details** |
| 36 | + - **Firestore Collection Name**: Enter the name of the Firestore collection you want to link. |
| 37 | + - **Data Type**: Choose an existing data type from your project or create a new one to represent the entities stored in the Firestore collection. |
| 38 | + See [Data type](/guides/data_type) for more details about Data type. |
| 39 | +  |
| 40 | + |
| 41 | +4. **Save the Association** |
| 42 | + Once saved, ComposeFlow will recognize the documents in the Firestore collection as a list of entities of the specified data type. |
| 43 | + |
| 44 | +5. **Edit Data Type Fields (Optional)** |
| 45 | + You can customize the fields of the associated data type by editing them in the right-hand pane after creating the association. |
| 46 | +  |
| 47 | +</Steps> |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +### 2. What Happens After Association |
| 52 | + |
| 53 | +Once you associate a Firestore collection with a data type, two key features become available: |
| 54 | + |
| 55 | +#### A. "Firestore" Actions |
| 56 | + |
| 57 | +- **Visibility**: |
| 58 | + The set of Firestore related actions such as "Save to Firestore" becomes visible in the list of available actions. |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | +- **Usage**: |
| 63 | + You can save an entity to the associated Firestore collection by invoking this action. |
| 64 | + |
| 65 | + |
| 66 | + |
| 67 | +#### B. Firestore Collection as a State |
| 68 | + |
| 69 | +- **Visibility**: |
| 70 | + The associated Firestore collection is now accessible as part of the ComposeFlow states. |
| 71 | + |
| 72 | + |
| 73 | +- **Usage**: |
| 74 | + Assign the Firestore collection state to any value to query and retrieve the entities stored in the collection. |
| 75 | + |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Example Workflow |
| 80 | + |
| 81 | +1. Navigate to **Firestore** and associate the `ToDo` collection with a data type `Todo`. |
| 82 | +2. Customize the `ToDo` data type to include fields like `name`, `done`. |
| 83 | +3. Use the "Save to Firestore" action to add new ToDo item to the Firestore collection. |
| 84 | +4. Query the `ToDo` collection by assigning its state as dynamic items in the `LazyColumn`. |
| 85 | +5. After running the app, you can observe invoking the "Save to Firestore" action or adding a document from the Firestore console directly is instantly reflected in the running app |
| 86 | + |
| 87 | +--- |
| 88 | + |
| 89 | +## Key takeaways |
| 90 | + |
| 91 | +- Firestore integration in ComposeFlow simplifies the management of Firestore collections by directly linking them with structured data types. |
| 92 | +- Changes to data types or actions are instantly reflected in your project, ensuring consistency with your Firestore database. |
| 93 | + |
0 commit comments