Firebase CLI ช่วยให้คุณจัดการโปรเจ็กต์ Firebase ในไดเรกทอรีโปรเจ็กต์ในเครื่องที่ควบคุมเวอร์ชันได้ ซึ่งรวมถึงSQL Connect บริการในโปรเจ็กต์ เครื่องมือเชื่อมต่อสำหรับบริการเหล่านั้น และทรัพยากรต่างๆ เช่น สคีมา แหล่งที่มาของการค้นหาและการเปลี่ยนแปลงสำหรับเครื่องมือเชื่อมต่อแต่ละรายการ นอกจากนี้ CLI ยังช่วยให้คุณ ติดตั้งและใช้งานโปรแกรมจำลอง Firebase SQL Connect ได้ด้วย CLI เป็นทางเลือกที่มีประสิทธิภาพ แทนการทำงานในคอนโซล Firebase
ดูวิธีการติดตั้งการทดลองใช้ Firebase CLI สำหรับ โปรแกรม Private Preview และคำสั่ง CLI ที่เกี่ยวข้องกับSQL Connect ได้ที่ ข้อมูลอ้างอิง Firebase CLI
Firebaseคู่มืออ้างอิงนี้จะอธิบายข้อมูลต่อไปนี้
- รายการเฉพาะของ SQL Connect ในไฟล์การกำหนดค่าโปรเจ็กต์
firebase.json - การกำหนดค่า SQL Connect ใน
dataconnect.yamlและconnector.yaml
ไฟล์การกำหนดค่าโปรเจ็กต์ Firebase
ข้อมูลอ้างอิงการกำหนดค่า firebase.json
ใช้คีย์ dataconnect เพื่อกำหนดค่าบริการ SQL Connect
อย่างน้อย 1 รายการในโปรเจ็กต์
dataconnect: {
source: string // Path to the directory containing the dataconnect.yaml service file.
}
ข้อมูลอ้างอิงการกำหนดค่า dataconnect.yaml
ไฟล์ dataconnect.yaml จะจัดเก็บข้อมูลการกำหนดค่าเกี่ยวกับตำแหน่งของแหล่งที่มาของสคีมาแอปพลิเคชัน แหล่งที่มาของเครื่องมือเชื่อมต่อ และข้อมูลการเชื่อมต่อแหล่งข้อมูล นอกจากนี้ ไฟล์นี้ยังทำหน้าที่เป็นตัวระบุไดเรกทอรีโปรเจ็กต์สำหรับ
Firebase CLI ด้วย
คีย์ 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.
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