ข้อมูลอ้างอิงไฟล์การกำหนดค่า Data Connect

Firebase CLI ช่วยให้คุณจัดการโปรเจ็กต์ Firebase ในไดเรกทอรีโปรเจ็กต์ในเครื่องที่ควบคุมเวอร์ชันได้ ซึ่งรวมถึงData Connect บริการในโปรเจ็กต์ ตัวเชื่อมต่อสำหรับบริการเหล่านั้น และทรัพยากรต่างๆ เช่น สคีมา แหล่งที่มาของคําค้นหาและการเปลี่ยนแปลงสําหรับตัวเชื่อมต่อแต่ละรายการ นอกจากนี้ CLI ยังช่วยให้คุณ ติดตั้งและใช้งานโปรแกรมจำลอง Firebase Data Connect ได้ด้วย CLI เป็นFirebaseคอนโซลทางเลือกที่มีประสิทธิภาพ

ดูวิธีการติดตั้งFirebaseการทดลอง CLI สำหรับ โปรแกรมตัวอย่างแบบส่วนตัวและคำสั่ง CLI ที่เกี่ยวข้องกับ Data Connect ได้ที่ข้อมูลอ้างอิง CLI

คู่มืออ้างอิงนี้จะบันทึกข้อมูลต่อไปนี้

  • Data Connect ในไฟล์การกำหนดค่าโปรเจ็กต์ firebase.json
  • การกำหนดค่า Data Connect ใน dataconnect.yaml และ connector.yaml

ไฟล์การกำหนดค่าโปรเจ็กต์ Firebase

ข้อมูลอ้างอิงการกำหนดค่า firebase.json

ใช้ปุ่ม dataconnect เพื่อกำหนดค่าบริการอย่างน้อย 1 รายการ Data Connect ในโปรเจ็กต์

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

ข้อมูลอ้างอิงการกำหนดค่า dataconnect.yaml

ไฟล์ dataconnect.yaml จะจัดเก็บข้อมูลการกำหนดค่าเกี่ยวกับตำแหน่งของแหล่งที่มาของสคีมาแอปพลิเคชัน แหล่งที่มาของตัวเชื่อมต่อ และข้อมูลการเชื่อมต่อแหล่งข้อมูล นอกจากนี้ ไฟล์นี้ยังทำหน้าที่เป็นตัวระบุไดเรกทอรีโปรเจ็กต์สำหรับ Firebase CLI ด้วย

ปุ่ม schemaValidation จะควบคุมระดับการตรวจสอบความถูกต้องของสคีมาที่ดำเนินการ เมื่อย้ายข้อมูลสคีมาระหว่างการติดตั้งใช้งาน หากไม่ได้ตั้งค่าไว้ ลักษณะการทำงานของคำสั่ง dataconect:sql:migrate คือการใช้การเปลี่ยนแปลงที่เข้ากันได้และแจ้งให้คุณทราบก่อนที่จะดำเนินการเปลี่ยนแปลงที่เข้มงวด เมื่อตั้งค่าแล้ว ลักษณะการทำงานจะเป็นดังนี้

  • โหมด STRICT สคีมาฐานข้อมูลต้องตรงกับสคีมาแอปพลิเคชันทุกประการก่อนจึงจะสามารถติดตั้งใช้งานสคีมาแอปพลิเคชันได้ ระบบจะลบตารางหรือคอลัมน์ที่ไม่ได้ใช้ในData Connectสคีมา ออกจากฐานข้อมูล
  • โหมด COMPATIBLE สคีมาฐานข้อมูลต้องเข้ากันได้กับสคีมาแอปพลิเคชันก่อนจึงจะสามารถติดตั้งใช้งานสคีมาแอปพลิเคชันได้ การเปลี่ยนแปลงเพิ่มเติมถือเป็นตัวเลือก ความเข้ากันได้หมายความว่าการย้ายข้อมูลสคีมา จะอิงตามสคีมาของแอปพลิเคชันที่คุณเขียน ระบบจะไม่แก้ไของค์ประกอบใน ฐานข้อมูลที่สคีมาแอปพลิเคชันไม่ได้ใช้ ดังนั้นหลังจากที่ติดตั้งใช้งานแล้ว Backend อาจมีสคีมา ตาราง และคอลัมน์ที่ไม่ได้ใช้

ค่าสำหรับคีย์อื่นๆ ในไฟล์นี้จะอธิบายไว้ในความคิดเห็นด้านล่าง

# The top-level Firebase Data Connect YAML file.

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

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

# The location of the Firebase Data 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 CloudSQL instance resource.
        # Required.
        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 Data 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. Recommend @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
    # 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. Recommend dataconnect_generated
      - package: 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.
        package: 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: @firebasegen-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 dart package to be created.
        # Required. Recommend dataconnect_generated
      - package: string