Firebase CLI 可讓您在可控管版本的本機專案目錄中管理 Firebase 專案。包括專案中的服務、這些服務的連接器,以及每個連接器的結構定義、查詢和變動來源等資源。Data Connect您也可以使用 CLI 安裝及操作 Firebase Data Connect 模擬器。與 Firebase 控制台相比,CLI 是更有效率的替代方案。
如需安裝 Private Preview 計畫的 Firebase CLI 實驗版,以及 Data Connect 相關 CLI 指令的操作說明,請參閱 CLI 參考資料。
本參考指南涵蓋以下內容:
firebase.json專案設定檔中的 Data Connect 專用項目。dataconnect.yaml和connector.yaml中的 Data Connect 設定。
Firebase 專案設定檔
firebase.json 設定參考資料
使用 dataconnect 鍵在專案中設定一或多個 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模式。資料庫結構定義必須與應用程式結構定義相容,應用程式結構定義才能部署;任何額外變更都視為選用。相容表示結構定義遷移作業是根據您編寫的應用程式結構定義進行。應用程式結構定義未使用的資料庫元素不會修改。因此,部署後端時,可能會包含未使用的結構定義、資料表和資料欄。
這個檔案中其他鍵的值說明如下方註解。
# 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