Thông tin tham khảo về tệp cấu hình SQL Connect

Firebase CLI cho phép bạn quản lý các dự án Firebase trong một thư mục dự án cục bộ, có thể kiểm soát phiên bản. Điều này bao gồm SQL Connect các dịch vụ trong dự án, trình kết nối cho các dịch vụ đó và các tài nguyên như lược đồ, nguồn truy vấn và đột biến cho mỗi trình kết nối. CLI cũng cho phép bạn cài đặt và vận hành trình mô phỏng Firebase SQL Connect. CLI là một giải pháp thay thế hiệu quả cho việc làm việc trong bảng điều khiển Firebase.

Để biết hướng dẫn về cách cài đặt thử nghiệm CLI Firebase cho chương trình Bản dùng thử riêng tư và các lệnh CLI liên quan đến SQL Connect, hãy xem tài liệu tham khảo về CLI Firebase.

Tài liệu tham khảo này ghi lại:

  • Các mục dành riêng cho SQL Connect trong tệp cấu hình dự án firebase.json.
  • SQL Connect cấu hình trong dataconnect.yaml và connector.yaml.

Tệp cấu hình dự án Firebase

Tài liệu tham khảo về cấu hình firebase.json

Sử dụng các khoá dataconnect để định cấu hình một hoặc nhiều dịch vụ SQL Connect trong dự án của bạn.

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

Tài liệu tham khảo về cấu hình dataconnect.yaml

Tệp dataconnect.yaml lưu trữ thông tin cấu hình về vị trí của các nguồn giản đồ ứng dụng, nguồn trình kết nối và thông tin kết nối nguồn dữ liệu. Tệp này cũng đóng vai trò là một ký hiệu thư mục dự án cho Firebase CLI.

Khoá schemaValidation kiểm soát mức độ xác thực giản đồ được thực hiện khi giản đồ được di chuyển trong quá trình triển khai. Nếu không có giá trị nào được đặt, thì hành vi của lệnh dataconect:sql:migrate là áp dụng các thay đổi tương thích và nhắc bạn trước khi thực thi bất kỳ thay đổi nghiêm ngặt nào. Khi được đặt, hành vi sẽ như sau:

  • Chế độ STRICT. Giản đồ cơ sở dữ liệu phải khớp chính xác với giản đồ ứng dụng thì giản đồ ứng dụng mới có thể được triển khai. Mọi bảng hoặc cột không được dùng trong giản đồ SQL Connect của bạn sẽ bị xoá khỏi cơ sở dữ liệu.
  • Chế độ COMPATIBLE. Giản đồ cơ sở dữ liệu phải tương thích với giản đồ ứng dụng trước khi có thể triển khai giản đồ ứng dụng; mọi thay đổi bổ sung đều được coi là không bắt buộc. Tương thích có nghĩa là quá trình di chuyển giản đồ dựa trên giản đồ ứng dụng mà bạn viết. Các phần tử trong cơ sở dữ liệu không được giản đồ ứng dụng sử dụng sẽ không được sửa đổi. Do đó, sau khi triển khai, phần phụ trợ của bạn có thể chứa các giản đồ, bảng và cột không dùng đến.

Giá trị của các khoá khác trong tệp này được giải thích trong phần nhận xét bên dưới.

# 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]

Tệp YAML giả định cấu trúc thư mục mặc định (nhưng có thể định cấu hình) như sau:

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

Tài liệu tham khảo về cấu hình connector.yaml

Sử dụng connector.yaml để định cấu hình chế độ xác thực mặc định và các tuỳ chọn tạo 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