Interfejs wiersza poleceń Firebase umożliwia zarządzanie projektami Firebase w lokalnym, katalogu projektu, który podlega kontroli wersji. Obejmuje to SQL Connect usługi w projektach, łączniki do tych usług oraz zasoby, takie jak schemat, źródła zapytań i mutacji dla każdego łącznika. Interfejs wiersza poleceń umożliwia też instalowanie i obsługę emulatora Firebase SQL Connect. Interfejs wiersza poleceń jest wydajną alternatywą dla pracy w Firebase konsoli.
Instrukcje dotyczące instalowania eksperymentu z interfejsem wiersza poleceń Firebase w ramach programu Private Preview oraz polecenia interfejsu wiersza poleceń związane z SQL Connect znajdziesz w dokumentacji interfejsu wiersza poleceń Firebase.
Ten przewodnik zawiera informacje o:
- wpisach związanych z SQL Connect w pliku konfiguracji projektu
firebase.json. - konfiguracjach SQL Connect w
dataconnect.yamliconnector.yaml.
Pliki konfiguracji projektu w Firebase
Dokumentacja konfiguracji firebase.json
Użyj kluczy dataconnect, aby skonfigurować co najmniej 1 SQL Connect
usługę w projekcie.
dataconnect: {
source: string // Path to the directory containing the dataconnect.yaml service file.
}
Dokumentacja konfiguracji dataconnect.yaml
Plik dataconnect.yaml zawiera informacje o konfiguracji lokalizacji źródeł schematu aplikacji, źródeł łączników i informacji o połączeniu ze źródłem danych. Plik ten służy też jako identyfikator katalogu projektu dla
Firebase interfejsu wiersza poleceń.
Klucz schemaValidation określa poziom weryfikacji schematu wykonywanej podczas migracji schematów w trakcie wdrażania. Jeśli nie ustawisz żadnej wartości, polecenie dataconect:sql:migrate zastosuje zgodne zmiany i wyświetli prośbę o potwierdzenie przed wykonaniem jakichkolwiek zmian. Jeśli ustawisz wartość, zachowanie będzie takie:
- Tryb
STRICT. Przed wdrożeniem schematu aplikacji schemat bazy danych musi dokładnie odpowiadać schematowi aplikacji. Wszystkie tabele lub kolumny, które nie są używane w schemacie SQL Connect zostaną usunięte z bazy danych. - Tryb
COMPATIBLE. Przed wdrożeniem schematu aplikacji schemat bazy danych musi być zgodny ze schematem aplikacji. Wszelkie dodatkowe zmiany są opcjonalne. Zgodność oznacza, że migracje schematu są oparte na schemacie aplikacji, który piszesz. Elementy w bazie danych, które nie są używane przez schemat aplikacji, pozostają niezmienione. Dlatego po wdrożeniu backend może zawierać nieużywane schematy, tabele i kolumny.
Wartości innych kluczy w tym pliku są wyjaśnione w komentarzach poniżej.
# 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]
Plik YAML zakłada domyślną (ale konfigurowalną) strukturę katalogów:
./(project root)
/dataconnect
dataconnect.yaml
/schema
*.gql
/example
connector.yaml
*.gql
Dokumentacja konfiguracji connector.yaml
Użyj pliku connector.yaml, aby skonfigurować domyślny tryb uwierzytelniania i opcje generowania pakietu 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