با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
Firebase Data Connect یک شبیهساز محلی برای نمونهسازی سرتاسر و همچنین جریانهای یکپارچهسازی و استقرار مداوم (CI/CD) در اختیار شما قرار میدهد:
شبیه ساز Data Connect با یک نمونه پایگاه داده PGLite یکپارچه محلی تعامل دارد تا به شما امکان می دهد پرس و جوها و جهش ها را نمونه اولیه کنید و کد مشتری را در یک محیط کاملاً محلی آزمایش کنید.
شبیه ساز Data Connect همچنین می تواند برای کارهای غیر تعاملی استفاده شود. این به شما امکان میدهد تستهای خودکار را اجرا کنید و برای استفاده با گردشهای کاری CI/CD مناسب است. این زمانی مفید است که طرحواره های شما پایدار هستند و می خواهید کدهای سمت سرویس گیرنده را نمونه اولیه و آزمایش کنید.
این راهنما نصب و استفاده از شبیه ساز را با جزئیات بیشتری نسبت به شروع سریع پوشش می دهد.
شبیه ساز Data Connect نصب کنید
قبل از نصب Local Emulator Suite برای استفاده از شبیه ساز Data Connect ، به موارد زیر نیاز دارید:
Node.js نسخه 18.0 یا بالاتر.
Firebase CLI را نصب کرده و دایرکتوری پروژه را راه اندازی کنید
Firebase CLI را طبق راهنمای نصب نصب کنید. حتماً مرتباً بهروزرسانی کنید ، زیرا شبیهساز Data Connect با رفع اشکال و ویژگیهای جدید در حال توسعه فعال است.
اگر قبلاً این کار را انجام نداده اید، دایرکتوری کاری فعلی را به عنوان یک پروژه Firebase مقداردهی اولیه کنید، با دنبال کردن دستورات مشخص کنید از کدام محصولات استفاده کنید:
firebaseinit
پیکربندی Local Emulator Suite تنظیم یا تغییر دهید
اگر شبیه ساز Data Connect را از پسوند Firebase VS Code راه اندازی کرده اید، در صورت نیاز، شبیه ساز برای شما نصب شده است.
میتوانید از Firebase CLI برای نصب دستی شبیهساز به همراه سایر مؤلفههای انتخابی Local Emulator Suite استفاده کنید. این دستور یک جادوگر پیکربندی را راهاندازی میکند که به شما امکان میدهد شبیهسازهای مورد علاقه را انتخاب کنید، فایلهای باینری شبیهساز مربوطه را دانلود کنید و اگر پیشفرضها مناسب نیستند، پورتهای شبیهساز را تنظیم کنید.
firebaseinitemulators
پس از نصب یک شبیهساز، تا زمانی که نسخه Firebase CLI خود را بهروزرسانی نکنید، هیچ بررسی بهروزرسانی انجام نمیشود و هیچ بارگیری خودکار اضافی انجام نمیشود.
یک پروژه Firebase را انتخاب کنید
در جریان راه اندازی، Firebase CLI از شما می خواهد که یک پروژه Firebase را انتخاب یا ایجاد کنید. اگر پروژه موجودی را که با Data Connect در کنسول Firebase راه اندازی کرده اید انتخاب کنید، پیکربندی که در آنجا انتخاب کرده اید پیشنهاد می شود.
شبیه ساز را راه اندازی کنید
شبیه ساز را پیکربندی کنید
اجرای جریان firebase init شما را از طریق گزینه های تنظیم شبیه ساز راهنمایی می کند. مانند سایر شبیه سازها در Local Emulator Suite ، پارامترهای پیکربندی در فایل های پروژه محلی ذخیره می شوند.
فایل firebase.json شما حاوی تخصیص پورت شبیه ساز است.
کلید emulators:ui برای شبیه ساز Data Connect اعمال نمی شود.
با منابع محلی و تولیدی Data Connect کار کنید
اگر میخواهید مطمئن شوید که بر منابع تولید تأثیر نمیگذارد، یک شناسه پروژه demo- تنظیم کنید یا مطمئن شوید که کد مشتری شما برای اتصال به شبیهساز، همانطور که در بخش بعدی بحث شد، ابزاری است.
شبیه ساز را راه اندازی کنید
اگر شبیه ساز را به صورت غیر تعاملی اجرا می کنید، به عنوان مثال برای گردش های کاری CI/CD، آن را با گزینه exec شروع کنید.
firebaseemulators:exec./path/to/test-script.sh
اگر در حال ادغام پرس و جوها و جهش های از پیش تعریف شده در کد مشتری هستید و از شبیه ساز به طور خاص برای آزمایش کلاینت ها استفاده می کنید، می توانید از گزینه start برای کار تعاملی استفاده کنید. همچنین می توانید شبیه ساز را از پسوند VS Code شروع کنید.
firebaseemulators:start
کد مشتری خود را برای صحبت با شبیه ساز ابزار کنید
پیکربندی درون برنامه ای یا کلاس های آزمایشی خود را برای تعامل با شبیه ساز Data Connect به شرح زیر تنظیم کنید.
جاوا اسکریپت
import{initializeApp}from"firebase/app";import{connectorConfig}from"@name-of-package";import{connectDataConnectEmulator,getDataConnect}from'firebase/data-connect';// TODO: Replace the following with your app's Firebase project configurationconstfirebaseConfig={//...};constapp=initializeApp(firebaseConfig);constdataConnect=getDataConnect(app,connectorConfig);connectDataConnectEmulator(dataConnect,"localhost",9399);// Make calls from your app
کاتلین اندروید
valconnector=MoviesConnector.instance// Connect to the emulator on "10.0.2.2:9399"connector.dataConnect.useEmulator()// (Alternatively) if you're running your emulator on non-default port:connector.dataConnect.useEmulator(port=9999)// Make calls from your app
iOS
let connector = DataConnect.dataConnect(DefaultConnectorClient.connectorConfig)
// Connect to the emulator on "127.0.0.1:9399"
connector.useEmulator()
// (alternatively) if you're running your emulator on non-default port:
connector.useEmulator(port: 9999)
// Make calls from your app
از شبیه ساز برای آزمایش و ادغام مداوم استفاده کنید
تصاویر Local Emulator Suite را اجرا کنید
نصب و پیکربندی Local Emulator Suite با کانتینرها در یک راه اندازی معمولی CI ساده است.
چند موضوع قابل توجه است:
باینری های شبیه ساز در ~/.cache/firebase/emulators/ نصب و ذخیره می شوند. ممکن است بخواهید این مسیر را به پیکربندی کش CI خود اضافه کنید تا از دانلودهای مکرر جلوگیری کنید.
اگر فایل firebase.json در مخزن خود ندارید، باید یک آرگومان خط فرمان به emulators:start یا emulators:exec اضافه کنید تا مشخص کنید کدام شبیه سازها باید راه اندازی شوند. به عنوان مثال، --only dataconnect .
پایگاه داده خود را بین تست ها پاک کنید
برای بازنشانی محیط های آزمایشی خود بین اجراها، Firebase توصیه می کند:
نوشتن جهش های اختصاصی برای رسیدگی به موارد زیر:
در راه اندازی، یک نمونه پایگاه داده محلی را با داده های شروع پر کنید.
در حذف، داده های اصلاح شده را از نمونه پایگاه داده پس از آزمون حذف کنید.
چگونه شبیه ساز Data Connect با تولید متفاوت است
شبیه ساز Data Connect بسیاری از ویژگی های محصول سمت سرور را شبیه سازی می کند. با این حال، چند استثنا وجود دارد که باید از آنها آگاه بود:
نسخه و پیکربندی دقیق PGLite ممکن است با نسخه نمونه تولیدی Cloud SQL شما متفاوت باشد.
اگر از شبیهساز برای توسعه با ادغام pgvector و Vertex API Data Connect استفاده میکنید، تماسها با Cloud Vertex API مستقیماً انجام میشود، نه از طریق یکپارچهسازی Vertex در Cloud SQL. با این حال، تماسها با API تولیدی همچنان برقرار است، به این معنی که شما باید از یک پروژه Firebase واقعی استفاده کنید، نمیتوانید از یک پروژه demo- استفاده کنید و هزینههای Vertex API متحمل میشوند.
تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-25 بهوقت ساعت هماهنگ جهانی."],[],[],null,["\u003cbr /\u003e\n\nFirebase Data Connect provides you with a local emulator for end-to-end\nprototyping as well as continuous integration and continuous deployment\n(CI/CD) flows:\n\n- The Data Connect emulator interacts with a local integrated PGLite database instance to let you prototype queries and mutations and test client code in a fully local environment.\n- The Data Connect emulator can also be used for non-interactive work. It lets you run automated tests and is suitable for use with CI/CD workflows. This is useful when your schemas are stable and you want to prototype and test client-side code.\n\nThis guide covers installation and usage of the emulator in more detail than\nthe quickstart.\n\nInstall the Data Connect emulator\n\nBefore installing the Local Emulator Suite to use the Data Connect\nemulator, you will need:\n\n- Node.js version 18.0 or higher.\n\nInstall the Firebase CLI and set up project directory **Note:** If you've followed the [Get started with Firebase Data Connect](/docs/data-connect/quickstart) guide, you can skip this section.\n\n1. Install the Firebase CLI, [following the installation guide](/docs/cli).\n Be sure to [update regularly](/docs/cli#update-cli), since the\n Data Connect emulator is under active development with bug fixes and\n new features.\n\n2. If you haven't already done so, initialize the current working directory as\n a Firebase project, following prompts to specify which products to use:\n\n firebase init\n\nSet or modify the Local Emulator Suite configuration\n\nIf you started the Data Connect emulator from the Firebase VS Code\nextension, the emulator was installed for you, if needed.\n\nYou can use the Firebase CLI to manually install the emulator along with\nother selected components of the Local Emulator Suite. This command starts a\nconfiguration wizard that lets you select emulators of interest, download the\ncorresponding emulator binary files, and set emulator ports if the defaults are\nnot appropriate. \n\n firebase init emulators\n\nOnce an emulator is installed, no update checks are performed and no additional\nautomatic downloads will occur until you update your Firebase CLI version.\n\nChoose a Firebase project\n\nIn the setup flow, the Firebase CLI prompts you to choose or create a\nFirebase project. If you choose an existing project you've set up with\nData Connect in the Firebase console, the configuration you chose\nthere will be suggested.\n\nSet up the emulator **Note:** Usage of the emulator in the Firebase Data Connect VS Code extension is covered in [Get started with Firebase Data Connect](/docs/data-connect/quickstart).\n\nConfigure the emulator\n\nRunning the `firebase init` flow will guide you through emulator setup options.\nLike other emulators in the Local Emulator Suite, configuration parameters\nare stored in local project files.\n\n- Your `firebase.json` file contains emulator port assignments.\n - The `emulators:ui` key does not apply to the Data Connect emulator.\n\nWork with local and production Data Connect resources\n\nIf you want to be sure not to impact production resources, set a `demo-`\nprojectID or make sure your client code is instrumented to connect to\nthe emulator, as discussed in a later section.\n\nStart the emulator\n\nIf you're running the emulator non-interactively, for example for CI/CD\nworkflows, start it with the `exec` option. \n\n firebase emulators:exec ./path/to/test-script.sh\n\nIf you're integrating predefined queries and mutations in client code and are\nusing the emulator specifically for testing clients, you can use the `start`\noption for interactive work. You can also start the emulator from the VS Code\nextension. \n\n firebase emulators:start\n\n| **Note:** When you start the emulator with `firebase emulators:start`, SDK code will be automatically generated just as if you had run `firebase sdk:generate`.\n\nInstrument your client code to talk to the emulator\n\nSet up your in-app configuration or test classes to interact with the\nData Connect emulator as follows. \n\nJavaScript \n\n```javascript\nimport { initializeApp } from \"firebase/app\";\nimport { connectorConfig } from \"@name-of-package\";\nimport { connectDataConnectEmulator, getDataConnect } from 'firebase/data-connect';\n\n// TODO: Replace the following with your app's Firebase project configuration\nconst firebaseConfig = {\n //...\n};\n\nconst app = initializeApp(firebaseConfig);\n\nconst dataConnect = getDataConnect(app, connectorConfig);\nconnectDataConnectEmulator(dataConnect, \"localhost\", 9399);\n\n// Make calls from your app\n \n```\n\nKotlin Android \n\n```kotlin\nval connector = MoviesConnector.instance\n\n// Connect to the emulator on \"10.0.2.2:9399\"\nconnector.dataConnect.useEmulator()\n\n// (Alternatively) if you're running your emulator on non-default port:\nconnector.dataConnect.useEmulator(port = 9999)\n\n// Make calls from your app\n \n```\n\niOS \n\n```text\nlet connector = DataConnect.dataConnect(DefaultConnectorClient.connectorConfig)\n\n// Connect to the emulator on \"127.0.0.1:9399\"\nconnector.useEmulator()\n\n// (alternatively) if you're running your emulator on non-default port:\nconnector.useEmulator(port: 9999)\n\n// Make calls from your app\n \n```\n\nUse the emulator for testing and continuous integration\n\nRun containerized Local Emulator Suite images\n\nInstallation and configuration of the Local Emulator Suite with containers\nin a typical CI setup is straightforward.\n\nThere are a few issues to note:\n\n- Emulator binaries are installed and cached at `~/.cache/firebase/emulators/`. You may want to add this path to your CI cache configuration to avoid repeated downloads.\n- If you don't have a `firebase.json` file in your repository, you must add a command line argument to the `emulators:start` or `emulators:exec` command to specify which emulators should be started. For example, `--only dataconnect`.\n\nClear your database between tests\n\nTo reset your test environments between runs, Firebase recommends:\n\n- Writing dedicated mutations to handle the following:\n - In setup, populate a local database instance with starting data.\n - In teardown, delete modified data from post-test database instance.\n\nHow the Data Connect emulator differs from production\n\nThe Data Connect emulator simulates many features of the server-side\nproduct. However, there are some exceptions to be aware of:\n\n- The version and detailed configuration of PGLite may differ from the version of your production Cloud SQL instance.\n- If you're using the emulator to develop with Data Connect's pgvector and Vertex API integration, calls to the Cloud Vertex API are made directly, rather than through Cloud SQL's Vertex integration. However, calls to the production API are still made, meaning you must use a real Firebase project, cannot use a `demo-` project, and costs of the Vertex API will be incurred."]]