History Firebase evolved from Evolve Company in 2011
History • Firebase evolved from Evolve Company in 2011. • A prior startup founded by James Tamplin and Andrew Lee. • And then, separate as a “Firebase Company” in April 2012. • Firebase was acquired by Google in October 2015. • In January 2017, Google acquires Fabric and Crashlytics from Twitter. • Firebase was been lunching Cloud Firestore, a Document Database, in October 3, 2017.
Firebase is a backend service developed by Google itself, enabling a bunch various features to the developer with easy integration strategies. A Backend service provide web/mobile developers a way to link their apps to a backend cloud storage and APIs exposed by back end applications.
Firebase
Realtime Database changed how we build apps Serverless Real-time Offline
Two things we’ve long wanted to improve User: { Lena: { birthday: 11/01/2017 address: Amsterdam }, ……. }, Friends: { Lena: {Tim: true}, …. } Simpler Data modeling & querying Scale without sharding
Introduction to Cloud Firestore Flexible , Scalable database Data ����������� � Realtime Listener��� application � data ������ sync ������� Offline �� support ���� network ������ sync ������� Cloud-hosted ������� No SQL database ������� native SDKs ������������� Native Node. js, Java, Python, and Go SDKs, in addition to REST and RPC APIs ��������
Data Structure Document Collection
YES Totally…no. . Just…no Wrong
Truly Serverless Firebase Auth Security Rules Cloud Functions App+ Client SDKs Cloud Firestore Firebase Hosting
Powered by Google Cloud’s Infrastructure Scalable Serverless Reliable & available
Realtime Database
Firebase Cloud Firestore v/s Firebase Realtime Database Nowadays, Firebase brought a new feature “Cloud Firestore. ” which is similar to “Firebase Realtime database”. “Realtime database” is structured as a JSON tree. “Cloud Firestore” is stored data in a documents which is a set of key-value pair and collection formats.
More Structure data Realtime Database stored data in JSON tree but Cloud Firestored data in documents which is very similar to JSON.
Better Querying In the Realtime database, We can only sort or filter on a property in a single query, not both sort and filter on a property while In the Cloud Fire. Store, You can chain filters and combine filtering and sorting on a property in a single query. If you want to fetch data in descending order then Cloud fire. Store is very useful for you but in the Realtime database, There is no available any query for it. You can also chain multiple “where” methods to create more specific queries (logical AND) in Cloud Fire. Store.
Pricing
Usage Realtime Database is Firebase's original database. It's an efficient, low-latency solution for mobile apps that require synced states across clients in realtime. Cloud Firestore is Firebase's new flagship database for mobile app development. It improves on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales better than the Realtime Database.
Why Should we use? ?
Flexibility DBMS ���Hierarchical data Structures ������������������� Data ������ Documents���������� collections ������ Firestore �������� ���Documents ������ complex nested objects ���sub-collections ������������� �
Storing Data in Cloud Firestore
Expressive Querying Simple Queries Create a reference to the cities collection Collection. Reference cities. Ref = db. collection("cities"); Create a query against the collection. Query query = cities. Ref. where. Equal. To("state", "CA"); Query capital. Cities = db. collection("cities"). where. Equal. To("capital", true); The where() method takes three parameters: a field to filter on, a comparison operation, and a value. The comparison can be <, <=, ==, >, or >= cities. Ref. where. Equal. To("state", "CA"); cities. Ref. where. Less. Than("population", 100000); cities. Ref. where. Greater. Than. Or. Equal. To("name", "San Francisco");
Expressive Querying Compound Queries(Right) cities. Ref. where. Equal. To("state", "CO"). where. Equal. To("name", "Denver"); cities. Ref. where. Equal. To("state", "CA"). where. Less. Than("population", 1000000); cities. Ref. where. Greater. Than. Or. Equal. To("state", "CA") . where. Less. Than. Or. Equal. To("state", "IN"); cities. Ref. where. Equal. To("state", "CA") . where. Greater. Than("population", 1000000); Invalid Filter ranged (X) cities. Ref. where. Greater. Than. Or. Equal. To("state", "CA") . where. Greater. Than ("population", 100000);
Order and limit data Valid: Range filters and order. By on the same field cities. Ref. order. By("name"). limit(3); cities. Ref. order. By("name", Direction. DESCENDING). limit(3); Invalid : Range Filters and first order. By on the different field cities. Ref. where. Greater. Than("population", 100000). order. By("country");
Paginate Data with Query Cursors Query cursors define the start and end points for a query, allowing you to: • Return a subset of the data. • Paginate query results. However, to define a specific range for a query, you should use the where() method described in Simple Queries.
Pagination Example
// Construct query for first 25 cities, ordered by population Query first = db. collection("cities") . order. By("population") . limit(25); first. get() . add. On. Success. Listener(new On. Success. Listener<Query. Snapshot>() { @Override public void on. Success(Query. Snapshot document. Snapshots) { // Get the last visible document Document. Snapshot last. Visible = document. Snapshots. get. Documents() . get(document. Snapshots. size() -1); } }); // Construct a new query starting at this document, // get the next 25 cities. Query next = db. collection("cities") . order. By("population"). start. After(last. Visible). limit(25); // Use the query for pagination
Add a simple cursor to a query start. At(A) and start. After(A) //Get all cities with a population >= 100, 000 , ordered by population db. collection(“cities”). order. By(“population”). start. At(100000); end. At(A) and end. Before(A) //Get all cities with a population <=100, 000, ordered by population db. collection(“cities”). order. By(“population”). end. At(100000);
Set multiple cursor conditions Cities Name State Yangon Hlaing Yangon Sanchaung Yangon La. Thar //Will return all Yangon db. collection(“cities”). order. By(“name”). order. By(“state”). start. At(“Yangon”); //Will return “Yangon, Sanchaung” and “Yangon, La. Thar” db. collection(“cities”). order. By(“name”). order. By(“state”). start. At(“Yangon”, ”Sanchaung”);
Manage Indexes in Cloud Firestore • Cloud Firestore requires an index for every query, to ensure the best performance. • All document fields are automatically indexed, so queries that only use equality clauses don't need additional indexes. • If you attempt a compound query with a range clause that doesn't map to an existing index, you receive an error.
Secure Data with Cloud Firestore offers robust access management and authentication through two different methods, depending on the client libraries you use. For mobile and web client libraries, use Firebase Authentication and Cloud Firestore Security Rules. For server client libraries, use Cloud Identity and Access Management (IAM). Setup Cloud Firestore Security Rules service cloud. firestore{ match/databases/{database}/documents{ match/{documents=**}{ allow read, write: if false; } } }
Public // Anyone can read or write to the database, even non-users of your app. service cloud. firestore { match /databases/{database}/documents { // Match all documents, recursively, with a wildcard and the "=**" recursive modifier match /{document=**} { allow read, write; } } } User // Grants a user access to a document matching their Auth user Id service cloud. firestore { match /databases/{database}/documents { // Collection named "users", document named after the user. Id match /users/{user. Id} { allow read, write: if request. auth. uid == user. Id; } }
Private // Access to documents through the Cloud Firestore mobile/web // client libraries is completely disallowed. Documents may still be // accessible through the Cloud Firestore server client libraries; // the Cloud Firestore REST and RPC APIs; and the Cloud Datastore // client libraries and APIs. service cloud. firestore { match /databases/{database}/documents { match /{document=**} { allow read, write: if false; } } }
Libraries and Frameworks A-Frame Angular Backbone. js Flutter React Redux Vue. js
- Slides: 43