پایگاه داده بلادرنگ فایربیس (Firebase Realtime Database) یک پایگاه داده ابری است. دادهها به صورت JSON ذخیره میشوند و به صورت بلادرنگ با هر کلاینت متصل همگامسازی میشوند. وقتی شما برنامههای چند پلتفرمی را با استفاده از SDK های اندروید، اپل و جاوا اسکریپت ما میسازید، همه کلاینتهای شما یک نمونه پایگاه داده بلادرنگ را به اشتراک میگذارند و به طور خودکار جدیدترین دادهها را دریافت میکنند.
پیشنیازها
If you haven't already, install the Firebase JS SDK and initialize Firebase .
ایجاد یک پایگاه داده
Navigate to the Realtime Database section of the Firebase console . You'll be prompted to select an existing Firebase project. Follow the database creation workflow.
Select a starting mode for your Firebase Security Rules :
- حالت تست
برای شروع کار با کتابخانههای کلاینت موبایل و وب خوب است، اما به هر کسی اجازه میدهد دادههای شما را بخواند و بازنویسی کند. پس از آزمایش، حتماً بخش « درک قوانین پایگاه داده بلادرنگ Firebase» را مرور کنید.
To get started with the web, Apple, or Android SDK, select testmode.
- حالت قفل شده
Denies all reads and writes from mobile and web clients. Your authenticated application servers can still access your database.
مکانی را برای پایگاه داده انتخاب کنید.
Depending on the location of the database , the URL for the new database will be in one of the following forms:
DATABASE_NAME .firebaseio.com(for databases inus-central1)DATABASE_NAME . REGION .firebasedatabase.app(for databases in all other locations)
روی انجام شد کلیک کنید.
When you enable Realtime Database , it also enables the API in the Cloud API Manager .
پیکربندی Realtime Database Security Rules
Realtime Database یک زبان قوانین اعلانی ارائه میدهد که به شما امکان میدهد نحوه ساختاردهی دادههای خود، نحوه فهرستبندی آنها و زمان خواندن و نوشتن دادهها را تعریف کنید.
Add the Realtime Database JS SDK and initialize Realtime Database
You must specify your Realtime Database URL when initializing the JavaScript SDK.
شما میتوانید آدرس اینترنتی Realtime Database خود را در بخش Realtime Database در کنسول Firebase پیدا کنید. بسته به موقعیت پایگاه داده ، آدرس اینترنتی پایگاه داده به یکی از شکلهای زیر خواهد بود:
https:// DATABASE_NAME .firebaseio.com(for databases inus-central1)https:// DATABASE_NAME . REGION .firebasedatabase.app(for databases in all other locations)
Initialize the SDK using the following code snippet:
Web
import { initializeApp } from "firebase/app"; import { getDatabase } from "firebase/database"; // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/learn-more#config-object const firebaseConfig = { // ... // The value of `databaseURL` depends on the location of the database databaseURL: "https://DATABASE_NAME.firebaseio.com", }; // Initialize Firebase const app = initializeApp(firebaseConfig); // Initialize Realtime Database and get a reference to the service const database = getDatabase(app);
Web
import firebase from "firebase/app"; import "firebase/compat/database"; // TODO: Replace the following with your app's Firebase project configuration // See: https://firebase.google.com/docs/web/learn-more#config-object const firebaseConfig = { // ... // The value of `databaseURL` depends on the location of the database databaseURL: "https://DATABASE_NAME.firebaseio.com", }; // Initialize Firebase firebase.initializeApp(firebaseConfig); // Initialize Realtime Database and get a reference to the service const database = firebase.database();
You're ready to start using the Firebase Realtime Database !
مراحل بعدی
Learn how to structure data for Realtime Database .
برای راهاندازی برنامه خود آماده شوید:
Enable App Check to help ensure that only your apps can access your databases.
Set up budget alerts for your project in the Google Cloud console.
داشبورد «استفاده و پرداخت» را در کنسول Firebase رصد کنید تا تصویری کلی از میزان استفاده پروژه خود در چندین سرویس Firebase داشته باشید. همچنین میتوانید برای اطلاعات دقیقتر در مورد میزان استفاده، از داشبورد «استفاده Realtime Database Usage ) بازدید کنید.
چک لیست راه اندازی Firebase را مرور کنید.