Справочник по файлу конфигурации SQL Connect

Интерфейс командной строки Firebase позволяет управлять проектами Firebase в локальном каталоге проекта с контролем версий. Это включает SQL Connect сервисы в ваших проектах, коннекторы для этих сервисов и ресурсы, такие как схема, источники запросов и изменений для каждого коннектора. CLI также позволяет установить и запустить эмулятор Firebase SQL Connect. CLI – это эффективная альтернатива работе в консоли Firebase.

Инструкции по установке экспериментальной версии интерфейса командной строки Firebase для программы закрытого тестирования и команды интерфейса командной строки, связанные с SQL Connect, можно найти в справочном руководстве по интерфейсу командной строки Firebase.

В этом справочном руководстве описаны:

  • Записи, относящиеся к SQL Connect, в файле конфигурации проекта firebase.json.
  • SQL Connect конфигураций в dataconnect.yaml и connector.yaml.

Файлы конфигурации проекта Firebase

Справочник по конфигурации firebase.json

Используйте ключи dataconnect, чтобы настроить один или несколько сервисов SQL Connect в проекте.

dataconnect: {
   source: string // Path to the directory containing the dataconnect.yaml service file.
}

Справочник по конфигурации dataconnect.yaml

В файле dataconnect.yaml хранится информация о конфигурации, в том числе о расположении источников схем приложений, источников коннекторов и подключений к источникам данных. Этот файл также служит указателем каталога проекта для CLI Firebase.

Ключ schemaValidation управляет уровнем проверки схемы, выполняемой при переносе схем во время развертывания. Если значение не задано, команда dataconect:sql:migrate применяет совместимые изменения и запрашивает подтверждение перед выполнением строгих изменений. Если правило настроено, оно работает следующим образом:

  • Режим "STRICT". Схема базы данных должна точно соответствовать схеме приложения, прежде чем можно будет развернуть схему приложения. Все таблицы и столбцы, которые не используются в схеме SQL Connect, будут удалены из базы данных.
  • Режим "COMPATIBLE". Перед развертыванием схемы приложения необходимо убедиться, что она совместима со схемой базы данных. Все остальные изменения необязательны. Совместимость означает, что перенос схемы основан на схеме приложения, которую вы пишете. Элементы базы данных, которые не используются схемой приложения, остаются без изменений. Поэтому после развертывания в серверной части могут остаться неиспользуемые схемы, таблицы и столбцы.

Значения других ключей в этом файле объясняются в комментариях ниже.

# The top-level Firebase SQL Connect YAML file.

# The Firebase SQL Connect API version to target.
# Optional. Defaults to the latest version.
specVersion: string

# The ID of the Firebase SQL Connect service resource.
# Required.
serviceId: string

# The location of the Firebase SQL Connect service.
# Required.
location: string

# Required.
schema:
  # Relative path to directory for schema definitions.
  # Recursively loads all .gql files in this directory.
  # Optional. If not present, defaults to ./schema.
  source: string
  # Datasource connection information.
  # Required.
  datasource:
    # Required.
    postgresql:
      # The name of the PostgreSQL database.
      # Required.
      database: string
      cloudSql:
        # The ID of the Cloud SQL instance resource.
        # Required. For supported PostgreSQL versions, see:
        # https://firebase.google.com/docs/sql-connect/manage-services-and-databases#supported-postgres-versions
        instanceId: string
        # Schema validation mode for schema migrations.
        # Defaults to unspecified/commented out, meaning you are prompted to
        # review all changes during migration.
        # If desired, uncomment and indicate one of "STRICT" or "COMPATIBLE".
        schemaValidation: string

# Required.
# Relative paths to directories for connector definitions.
# Recursively loads all .gql files in the listed directories.
# All directories specified MUST contain a connector.yaml file.
connectorDirs: [string]

В файле YAML предполагается следующая структура каталогов по умолчанию (ее можно изменить):

./(project root)
   /dataconnect
      dataconnect.yaml
      /schema
        *.gql
      /example
        connector.yaml
        *.gql

Справочник по конфигурации connector.yaml

Используйте connector.yaml, чтобы настроить режим аутентификации по умолчанию и параметры создания SDK.

# The connector-level YAML file.

# Required. The connector name of the Firebase SQL Connect connector resource.
connectorId: string

# Optional. If not specified, no generated libraries (i.e. type-safe SDKs) will
# be generated.
generate:
    # Optional.
    javascriptSdk:
        # Path to the directory that will be updated with the latest generated
        # web TypeScript SDK.
        # Required.
        outputDir: string
        # Name of the Javascript package to be created.
        # Required. Example: @dataconnect/generated
        package: string
        # Path to your package.json directory. If specified, the new generated
        # SDK will be installed in this path.
        # Optional. If not provided, the package will not be auto-installed for
        # you.
        packageJsonDir: string
        # Enable React framework bindings.
        # Optional. Default to false.
        react: Boolean
        # Enable Angular framework bindings.
        # Optional. Default to false.
        angular: Boolean
        # Enable and configure client-side caching for the generated SDK.
        # Optional. If the `clientCache` key is not present, caching is disabled.
        clientCache:
            # The maximum age allowed for cached results before fetching fresh
            # values. A value of "0" means that responses are cached, but the
            # client SDK will always fetch fresh values; the cached values are
            # only used when CACHE_ONLY is specified to executeQuery() and as the
            # initial result returned from subscribe().
            # Examples: "0", "30s", "1h30m"
            # Optional. Default: "0"
            maxAge: string
            # Configures how results are to be cached.
            # Optional. Only "memory" is allowed for JavaScript SDKs.
            storage: string
    # Optional.
    dartSdk:
        # Path to the directory that will be updated with the latest generated
        # Flutter Dart SDK.
        # Required.
        outputDir: string
        # Name of the Dart package to be created.
        # Required. Example: "dataconnect_generated"
        package: string
        # Enable and configure client-side caching for the generated SDK.
        # Optional. If the `clientCache` key is not present, caching is disabled.
        clientCache:
            # The maximum age allowed for cached results before fetching fresh
            # values. A value of "0" means that responses are cached, but the
            # client SDK will always fetch fresh values; the cached values are
            # only used when CACHE_ONLY is specified to execute() and as the
            # initial result returned from subscribe().
            # Examples: "0", "30s", "1h30m"
            # Optional. Default: "0"
            maxAge: string
            # Configures whether results are to be cached in persistent storage
            # or in memory ("persistent" or "memory").
            # Optional.
            # Default: "persistent" for Android and iOS targets, "memory" for web.
            storage: string
    # Optional.
    kotlinSdk:
        # Path to the directory that will be updated with the latest generated
        # Android SDK.
        # Required.
        outputDir: string
        # Name of the package to be created.
        # Required. Example: com.google.firebase.dataconnect.generated
        package: string
        # Enable and configure client-side caching for the generated SDK.
        # Optional. If the `clientCache` key is not present, caching is disabled.
        clientCache:
            # The maximum age allowed for cached results before fetching fresh
            # values. A value of "0" means that responses are cached, but the
            # client SDK will always fetch fresh values; the cached values are
            # only used when CACHE_ONLY is specified to execute().
            # Examples: "0", "30s", "1h30m"
            # Optional. Default: "0"
            maxAge: string
            # Configures whether results are to be cached in persistent storage
            # or in memory ("persistent" or "memory").
            # Optional. Default: persistent
            storage: string
    # Optional.
    adminNodeSdk:
        # Path to the directory that will be updated with the latest generated
        # Node Admin SDK.
        # Required.
        outputDir: string
        # Path to your package.json directory. If specified, the new generated
        # SDK will be installed in this path.
        # Optional. If not provided, the package will not be auto-installed for
        # you.
        packageJsonDir: string
        # Name of the package to be created (for example: @dataconnect/admin-generated).
        # Required.
        package: string
    # Optional.
    swiftSdk:
        # Path to the directory that will be updated with the latest generated
        # iOS Swift SDK.
        # Required.
        outputDir: string
        # Name of the Swift package to be created.
        # Required. Example: "FirebaseDataConnectGenerated"
        package: string
        # Enable and configure client-side caching for the generated SDK.
        # Optional. If the `clientCache` key is not present, caching is disabled.
        clientCache:
            # The maximum age allowed for cached results before fetching fresh
            # values. A value of "0" means that responses are cached, but the
            # client SDK will always fetch fresh values; the cached values are
            # only used when CACHE_ONLY is specified to execute().
            # Examples: "0", "30s", "1h30m"
            # Optional. Default: "0"
            maxAge: string
            # Configures whether results are to be cached in persistent storage
            # or in memory ("persistent" or "memory").
            # Optional. Default: persistent
            storage: string