You are on page 1of 26

Database Principles:

Firebase Databases
2023
Information Technology Department
Objectives
• Firebase database Functions.
• JSON format.
• Firebase Data model.
• Constructing a Realtime database
• Constructing a Cloud Firestore database.
What is Firebase?
• Firebase is a platform developed by Google for creating mobile and
web applications.
• It has a multiple services.
Firebase Features
• Real-time Database − Firebase supports JSON data and all users
connected to it receive live updates after every change.
• Authentication– We can use anonymous, password or different social
authentications.
• Hosting – The applications can be deployed over secured connection
to Firebase servers.
What sort of apps is Firebase good for?
There is no limit of the type of applications that can be heloped by
Google Firebase, such as:
• Mobile Applications (iOS, Android or Flutter)
• Web-based Applications
• Unity applications (game development platform)
Environment Setup
• Step 1 – Create a Firebase Account
• Step 2 – Create a Database
Step 1 – Create a Firebase Account
• You can create a Firebase account here.
https://firebase.google.com
Step 2 – Create a Database
Which product you should use in your application?

a. Realtime Database:
a realtime, cloud hosted, NoSQL database

b. Cloud Firestore:
a realtime, cloud hosted, NoSQL database
What is a Realtime Update?
The feature “realtime” updates to data as it changes in the database.
a. Realtime Database

• Data is stored as JSON objects.


• The Firebase Realtime Database is a cloud-hosted database.
• Data is synchronized in Realtime to every connected client.
• Firebase apps remain responsive even when the Realtime database is
offline.
• No need for an application server, everything is saved in the cloud.
• Data is scaled and sharded across multiple databases
But, What is JSON?
• JSON= JavaScript Object Notation
• JSON is an open standard file format and data interchange format.
• JSON stores and transmits data objects consisting of attribute/value
pairs and arrays between front and back ends.

Backend
Frontend
JSON Syntax
• A value in JSON can be:
• number
• String
• Function
• another object
• null
JSON Syntax
• Data is in name/value pairs
• Data is separated by
commas
• Curly braces hold objects
• Square brackets hold arrays

id language edition author


01 Java third Herbert Schildt
07 C++ second E.Balagurusamy
JSON Syntax

• A name/value pair consists of a field name (in double


quotes), followed by a colon, followed by a value:

"name":"John"
Write a JSON file
• Convert the following hierarchical data model into a set of JSON
documents: StaffNo = SL19
Name = Ahmed
Age = 30
City = Riyadh
OnVacation = False
STAFF
StaffNo = SL01
Name = Nora
Age = 42
City = Riyadh
OnVacation = True

StaffNo = SL90
Name = Hend
Age = 29
City = Riyadh
OnVacation = Null
Realtime database Steps:
• Open the notpad and write the JSON syntax for the given data model
and save it as staff.json
• Create a new project -> create a database in Realtime Firebase
database.
• Uplaod the JSON file (staff.json) to firebase.
The Output

StaffNo = SL19
Name = Ahmed
Age = 30
City = Riyadh
OnVacation = False
STAFF
StaffNo = SL01
Name = Nora
Age = 42
City = Riyadh
OnVacation = True

StaffNo = SL90
Name = Hend
Age = 29
City = Riyadh
OnVacation = Null
b. Cloud Firestore
Key features of Cloud Firestore include:
• Documents and collections structure.
• A powerful querying functions.
• iOS, Android, and Web SDKs with offline data access
• Real-time data synchronization
• Data replication with strong consistency
• Supports Node, Python, Go, and Java server SDKs
Cloud Firestore Data Model
Collection and Documents
A nested
collections and
douments
Terminalogy in Cloud Firestore
RDBMS (Relational Database) Cloud Firestore ( Doument Oriented Database)
Firebase Data Types
Object Data Type Example
Array [1, 2, 3]
Boolean false , true
Date and time 12:00 , 12-01-1999
Floating-point number 0.001
Geographical point (49°30'00"N, 123°30'00"W)
Integer 12
Null NULL
Text string Ahemd, Riyadh
Reference Referencing to another object
Consturct a Document-collection Sturucture using Cloud
Firestore
• Convert the following hierarchical data model into a set of documents
and collections: StaffNo = SL19
Name = Ahmed
Age = 30
City = Riyadh
OnVacation = False
STAFF
StaffNo = SL01
Name = Nora
Age = 42
City = Riyadh
OnVacation = True

StaffNo = SL90
Name = Hend
Age = 29
City = Riyadh
OnVacation = Null
The Output
Firebase Limitations
• Firebase free plan is limited to:
• 50 client Connections
• 100 MB of storage.

If you need more, then go with the paid Blaze plan.


References
• https://medium.com/firebase-developers/what-is-firebase-the-compl
ete-story-abridged-bcc730c5f2c0

• https://firebase.googleblog.com/2017/10/introducing-cloud-firestore.
html

• https://firebase.google.com/docs/samples

You might also like