All skills
firebase avatar

/firebase-data-connect-basics

@c2630ec official
by firebasefirebase/agent-skills461 stars
102

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.

  • 17 files
  • 122.7 KB
  • Updated last week
  • GitHub

Use this Skill: https://skilld.dev/gh/firebase/agent-skills/firebase-data-connect-basics

This session only. Nothing lands on disk.

referencesdk_flutter.md

≈875 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Flutter SDK

Consult this file when writing Flutter application code (Dart) that interacts with the SQL Connect backend.

Best Practices for Agents

  • Understand Operation Storage: SQL Connect queries and mutations are stored on the server like Cloud Functions. Whenever you update operations, you must regenerate the SDK and redeploy services that use it to avoid breaking clients.
  • Resilient Enum Handling: The generated SDK forces handling of unknown values for enumerations. Client code must unwrap the EnumValue object into either Known or Unknown to handle schema updates gracefully.
  • Use Ref for Subscriptions: Call .ref() on operation methods to get a QueryRef for advanced usage like subscriptions.
  • Builder Pattern for Optionals: Use the builder pattern for mutations with optional fields.

Installation

flutter pub add firebase_data_connect

Imports

import 'package:firebase_data_connect/firebase_data_connect.dart';
// Import generated connector
import 'generated/movies.dart'; 

Initialization

// For local development with emulator
MoviesConnector.instance.dataConnect.useDataConnectEmulator('127.0.0.1', 9399);

Calling Operations

Basic Query
final response = await MoviesConnector.instance.listMovies().execute();
print(response.data.movies);
Mutation with Optional Fields (Builder Pattern)
await MoviesConnector.instance.createMovie(
  title: 'Empire Strikes Back', 
  releaseYear: 1980, 
  genre: 'Sci-Fi' 
).rating(5).execute();

Resilient Enum Handling

When dealing with schema enumerations, use the forced unwrapping pattern to handle unknown values (e.g., when a new value is added to the backend but client is old).

final result = await MoviesConnector.instance.listMovies().execute();

if (result.data.movies.isNotEmpty) {
  handleEnumValue(result.data.movies[0].aspectratio);
}

void handleEnumValue(EnumValue<AspectRatio> aspectValue) {
  if (aspectValue.value != null) {
    switch(aspectValue.value!) {
      case AspectRatio.ACADEMY:
        print("Academy aspect");
        break;
      case AspectRatio.WIDESCREEN:
        print("Widescreen aspect");
        break;
      // Add other known cases...
    }
  } else {
    print("Unknown aspect ratio detected: ${aspectValue.stringValue}");
  }
}

Client-Side Caching

Enable caching in connector.yaml to reduce requests and support offline scenarios.

generate:
  dartSdk: # Or the appropriate block for your project
    outputDir: ../dart/
    package: "dataconnect_generated"
    clientCache:
      maxAge: 5s
      storage: memory # Or persistent for native

Use policies in code:

// Only serve cached values
await queryRef.execute(fetchPolicy: QueryFetchPolicy.cacheOnly);

// Unconditionally fetch fresh values
await queryRef.execute(fetchPolicy: QueryFetchPolicy.serverOnly);

Real-time Subscriptions

final queryRef = MoviesConnector.instance.getMovieById(id: "<MOVIE_ID>").ref();
final subscription = queryRef.subscribe().listen((result) {
  final movie = result.data.movie;
  if (movie != null) {
    updateUi(movie.title);
  }
});

Data Type Mapping Reference

  • GraphQL Timestamp -> Dart firebase_data_connect.Timestamp
  • GraphQL Int -> Dart int
  • GraphQL Date -> Dart DateTime
  • GraphQL UUID -> Dart string
  • GraphQL Float -> Dart double
  • GraphQL Boolean -> Dart bool

Source: SKILL.md on GitHub

No third-party reports yet.

Signed by skilld at c2630ec. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated last week
metadata
{
  "category": "Databases"
}

README badge

README badge for firebase/agent-skills/firebase-data-connect-basics