$npx -y skills add firebase/agent-skills --skill firebase-data-connect-basicsBuilds 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 ne
| 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 |