byfirebase· 35 skills
Builds and deploys Firebase SQL Connect (aka Firebase Data Connect) backends with PostgreSQL securely. Use when designing schemas with tables and relations, writing authorized queries and mutations, configuring real-time data updates, or generating type-safe SDKs. Use when you need a relational database with Firebase, or when the user mentions SQL Connect or Data Connect.
$npx -y skills add firebase/agent-skills --skill firebase-data-connect-basicsInstalls into the current project.
Run `npx skills use "https://github.com/firebase/agent-skills" --skill "firebase/agent-skills/firebase-data-connect-basics"` and follow the generated skill instructions now. Read its complete output, redirecting it to a temporary file first if necessary. Resolve relative paths from the supporting-files directory it provides.
Use the skills in "https://github.com/firebase/agent-skills" that are relevant to the current task. Run `npx skills add "https://github.com/firebase/agent-skills"` and select the relevant skills, then follow their instructions.
| 1 | # Firebase SQL Connect |
| 2 | |
| 3 | Firebase SQL Connect is a relational database service using Cloud SQL for |
| 4 | PostgreSQL with GraphQL schema, auto-generated queries/mutations, and type-safe |
| 5 | SDKs. |
| 6 | |
| 7 | > [!NOTE] **Product Rename**: Firebase Data Connect was renamed to **Firebase |
| 8 | > SQL Connect**. All instructions, references, and examples in this skill |
| 9 | > repository referring to "Data Connect" or "Firebase Data Connect" apply to |
| 10 | > "SQL Connect" and "Firebase SQL Connect" as well. |
| 11 | |
| 12 | ## Project Structure |
| 13 | |
| 14 | ```text |
| 15 | dataconnect/ |
| 16 | ├── dataconnect.yaml # Service configuration |
| 17 | ├── seed_data.gql # LOCAL ONLY — prototype/test data |
| 18 | ├── schema/ |
| 19 | │ └── schema.gql # Data model (types with @table) |
| 20 | └── connector/ |
| 21 | ├── connector.yaml # Connector config + SDK generation |
| 22 | ├── queries.gql # Queries |
| 23 | └── mutations.gql # Mutations |
| 24 | ``` |
| 25 | |
| 26 | ## Key Tools for Validation |
| 27 | |
| 28 | Rely on these two mechanisms to ensure project correctness: |
| 29 | |
| 30 | 1. **Review GraphQL Schema**: Both user-defined and generated extensions (in |
| 31 | `.dataconnect/schema/main/`). |
| 32 | 1. **Validate Operations**: Run |
| 33 | `npx -y firebase-tools@latest dataconnect:compile` against the schema. |
| 34 | |
| 35 | ## Operation Strategies: GraphQL vs. Native SQL |
| 36 | |
| 37 | Always default to **Native GraphQL**. **Native SQL lacks type safety** and |
| 38 | bypasses schema-enforced structures. Only use **Native SQL** when the user |
| 39 | explicitly requests it or when the task requires advanced database features. |
| 40 | |
| 41 | | Strategy | When to use | Implementation | |
| 42 | | ---------------------------- | ---------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- | |
| 43 | | **Native GraphQL** (Default) | Almost all use cases. Standard CRUD, basic filtering/sorting, simple relational joins. Requires full type safety. | Auto-generated fields (`movie_insert`, `movies`). Strong typing and schema enforcement. | |
| 44 | | **Native SQL** (Advanced) | PostgreSQL extensions (e.g., PostGIS), window functions (`RANK()`), complex aggregations, or highly tuned sub-queries. | Raw SQL string literals via `_select`, `_execute`, etc. Requires strict positional parameters (`$1`). No type safety. | |
| 45 | |
| 46 | ## Development Workflow |
| 47 | |
| 48 | Follow this strict workflow to build your application. You **must** read the |
| 49 | linked reference files for each step to understand the syntax and available |
| 50 | features. |
| 51 | |
| 52 | ### 1. Define Data Model (`schema/schema.gql`) |
| 53 | |
| 54 | Define your GraphQL types, tables, and relationships (which map to a Postgres |
| 55 | schema). |
| 56 | |
| 57 | > **Read [reference/schema.md](reference/schema.md)** for: |
| 58 | > |
| 59 | > - `@table`, `@col`, `@default` |
| 60 | > - Relationships (`@ref`, one-to-many, many-to-many) |
| 61 | > - Data types (UUID, Vector, JSON, etc.) |
| 62 | |
| 63 | ### 2. Define Authorized Operations (`connector/queries.gql`, `connector/mutations.gql`) |
| 64 | |
| 65 | Write the queries and mutations your client will use, including authorization |
| 66 | logic. SQL Connect is secure by default. |
| 67 | |
| 68 | > **Read [reference/operations.md](reference/operations.md)** for: |
| 69 | > |
| 70 | > - **Queries**: Filtering (`where`), Ordering (`orderBy`), Pagination |
| 71 | > (`limit`/`offset`). |
| 72 | > - **Mutations**: Create (`_insert`), Update (`_update`), Delete (`_delete`). |
| 73 | > - **Upserts**: Use `_upsert` to "insert or update" records (CRITICAL for user |
| 74 | > profiles). |
| 75 | > - **Transactions**: Use `@transaction` for multi-step atomic operations. Use |
| 76 | > `_expr: "response.<prevStep>"` to pass data between steps. |
| 77 | > |
| 78 | > **Read [reference/security.md](reference/security.md)** for authorization: |
| 79 | > |
| 80 | > - `@auth(level: ...)` for PUBLIC, USER, or NO_ACCESS. |
| 81 | > - `@check` and `@redact` for row-level security and validation. |
| 82 | > |
| 83 | > **Read [reference/realtime.md](reference/realtime.md)** for real-time |
| 84 | > subscriptions: |
| 85 | > |
| 86 | > - `@refresh` directive for time-based polling and event-driven updates. |
| 87 | > - CEL conditions to scope refresh triggers precisely. |
| 88 | > |
| 89 | > **Read [reference/native_sql.md](reference/native_sql.md)** for Native SQL |
| 90 | > operations: |
| 91 | > |
| 92 | > - Embedding raw SQL with `_select`, `_selectFirst`, `_execute` |
| 93 | > - Strict rules for positional parameters (`$1`, `$2`), quoting, and CTEs |
| 94 | > - Advanced PostgreSQL features (PostGIS, Window Functions) |
| 95 | |
| 96 | ### 3. Use type-safe SDK in your apps |
| 97 | |
| 98 | Generate type-safe code for your client platform. |
| 99 | |
| 100 | Configure SDK generation in `connector.yaml`: |
| 101 | |
| 102 | ```yaml |
| 103 | connectorId: my-connector |
| 104 | generate: |
| 105 | javascriptSdk: |
| 106 | outputDir: "../web-app/src/lib/dataconnect" |
| 107 | package: "@movie-app/dataconnect" |
| 108 | kotlinSdk: |
| 109 | outputDir: "../android-app/app/src/main/kotlin/com/example/dataconnect" |
| 110 | package: "com.example.dataconnect" |
| 111 | swiftSdk: |
| 112 | outputDir: "../ios-app/DataConnect" |
| 113 | ``` |
| 114 | |
| 115 | Generate SDKs: |
| 116 | |
| 117 | ```bash |
| 118 | npx -y firebase-tools@latest dataconnect:sdk:generate |
| 119 | ``` |
| 120 | |
| 121 | For platform-specific instructions on how to use the generated SDKs, read: |
| 122 | |
| 123 | - **Web (TypeScript)**: [reference/sdk_web.md](reference/sdk_web.md) |
| 124 | - **Android (Kotlin)**: [reference/sdk_android.md](reference/sdk_android.md) |
| 125 | - **iOS (Swift)**: [reference/sdk_ios.md](reference/sdk_ios.md) |
| 126 | - **Admin (Node.js)**: |
| 127 | [reference/sdk_admin_node.md](reference/sdk_admin_node.md) |
| 128 | - **Flutter (Dart)**: [reference/sdk_flutter.md](reference/sdk_flutter.md) |
| 129 | |
| 130 | ______________________________________________________________________ |
| 131 | |
| 132 | ## Feature Capability Map |
| 133 | |
| 134 | If you need to implement a specific feature, consult the mapped reference file: |
| 135 | |
| 136 | | Feature | Reference File | Key Concepts | |
| 137 | | :------------------------------ | :----------------------------------------------------------- | :------------------------------------------------- | |
| 138 | | **Data Modeling** | [reference/schema.md](reference/schema.md) | `@table`, `@unique`, `@index`, Relations | |
| 139 | | **Vector Search** | [reference/search.md](reference/search.md) | `Vector`, `@col(dataType: "vector")`, embeddings | |
| 140 | | **Full-Text Search** | [reference/search.md](reference/search.md) | `@searchable`, `movies_search` | |
| 141 | | **Upserting Data** | [reference/operations.md](reference/operations.md) | `_upsert` mutations | |
| 142 | | **Complex Filters** | [reference/operations.md](reference/operations.md) | `_or`, `_and`, `_not`, `eq`, `contains` | |
| 143 | | **Transactions** | [reference/operations.md](reference/operations.md) | `@transaction`, `response` binding | |
| 144 | | **Environment Config** | [reference/config.md](reference/config.md) | `dataconnect.yaml`, `connector.yaml` | |
| 145 | | **Realtime Subscriptions** | [reference/realtime.md](reference/realtime.md) | `@refresh`, `subscribe()`, auto-refresh | |
| 146 | | **Cloud Functions Integration** | [reference/cloud_functions.md](reference/cloud_functions.md) | `onMutationExecuted`, triggering events | |
| 147 | | **Data Seeding & Migrations** | [reference/data_seeding.md](reference/data_seeding.md) | `seed_data.gql`, `_insertMany`, Admin SDK bulk | |
| 148 | | **Starter Templates** | [templates.md](templates.md) | CRUD, user-owned resources, many-to-many, SDK init | |
| 149 | |
| 150 | ______________________________________________________________________ |
| 151 | |
| 152 | ## Deployment & CLI |
| 153 | |
| 154 | > **Read [reference/config.md](reference/config.md)** for deep dive on |
| 155 | > configuration. |
| 156 | |
| 157 | Follow these patterns based on your current task: |
| 158 | |
| 159 | ### How to initialize SQL Connect in a Firebase project |
| 160 | |
| 161 | 1. Understand the app idea. Ask clarification questions if unclear. |
| 162 | 1. Run `npx -y firebase-tools@latest init dataconnect`. |
| 163 | 1. Validate that the app template and generated SDK are setup. |
| 164 | |
| 165 | ### How to build apps using SQL Connect locally |
| 166 | |
| 167 | 1. Start the emulator: |
| 168 | `npx -y firebase-tools@latest emulators:start --only dataconnect`. |
| 169 | 1. Write schema and operations. |
| 170 | 1. Seed local test data into `seed_data.gql`. Read |
| 171 | [reference/data_seeding.md](reference/data_seeding.md#local-prototyping-data-seeding). |
| 172 | 1. Run `npx -y firebase-tools@latest dataconnect:compile` or |
| 173 | `npx -y firebase-tools@latest dataconnect:sdk:generate` to validate them. |
| 174 | 1. Use the operations in your app and build it. |
| 175 | |
| 176 | ### How to deploy SQL Connect to Cloud SQL |
| 177 | |
| 178 | 1. Run `npx -y firebase-tools@latest deploy --only dataconnect`. |
| 179 | |
| 180 | ## Examples |
| 181 | |
| 182 | For complete, working code examples of schemas and operations, see |
| 183 | **[examples.md](examples.md)**. |
| 184 | |
| 185 | For ready-to-use starter templates (CRUD, user-owned resources, many-to-many, |
| 186 | YAML configs, SDK init), see **[templates.md](templates.md)**. |