🔥 Firestore: scalable database

1.Introduction

Extension Name: Firestore
Cloud Firestore is Firebase’s newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database.

Latest Version: 1.1
Released: 2020-07-12T04:37:00Z
Last Updated: 2020-07-12T04:51:00Z

2.Documentation

Methods

• Initialize Firebase
Initializes the SDK.
image
Activate the firestore in your Firebase, in the rules, activate the reading and writing. In project settings in firebase, add your application. Download the google-service.json file and open it with a text editor, then get the following data:

"project_id" ➜ projectId;
"mobilesdk_app_id" ➜ aplicationId;
"current_key" ➜ apiKey.
persistent ~ boolean

Rules
Remember to change your rules at the firestore; in this example, you can read and write to your database.
image
Note: Unfortunately it is currently not possible to secure the database with Firebase Auth, perhaps this will only become possible when the kodular adds a firestore component.

Guide

• Get Document Query
Get a list of documents according to the query, returning it in “GotQuery”.
image
collectionReference ~ text
query ~ list

Key: queryType, Value:

• limit ~ text
Key: value, Value: (Limit of documents returned ~ number)
image

• where ~ text
Key: value, Value: ~ dictonary

  1. Key: fieldpath, Value: ~ text
  2. Key: opStr, Value: (“==”,”>”,”>=”,”<”,”<=”)
  3. Key: value, Value: (value to be compared)
    image

• orderBy ~ text
Key: value, Value: ~ dictonary

  1. Key: direction, Value: (“asc”, “desc”)
  2. Key: field, Value: ~ text
    image

• startAfter ~ text
Key: value, Value: (Start after that value)
image

• startAt ~ text
Key: value, Value: (Start at that value)
image

• endAt ~ text
*Key: value, Value: (end at that value)
image
• endBefore ~ text
Key: value, Value: (end before that value)
image

Example

In this example, all documents in the reference collection are left in ascending order relative to the “id” of the field and then a limit of 5 is placed.


Note: As we can see, the order of selection is from bottom to top in the list :arrow_up:.

• Set Document
Set the documents
image
documentReference ~ text
document ~ dictionary

• Set Field With Merge
Update one field, creating the document if it does not already exist.
image
documentReference ~ text
document ~ dictionary

Add Document
Add a new document with a generated id.
image
collectionReference ~ text
document ~ dictionary

• New Document
Create a new empty document with a specific name, if you want to create it by generating an id leave the documentName field empty.
image
collectionReference ~ text
documentName ~ text

• Updates Document
Updates the document.
image
collectionReference ~ text
document ~ dictionary

• Get All Docs
Gets the complete list of documents in the collection, returning to GotAllDocs.
image
collectionReference ~ text

• Register Listener
Register a listener and if there are changes to the collection it will return to OnListenerAdded, OnListenerModified, OnListenerRemoved.
image
collectionRefernce ~ text

• Remove Listener
Removes the listener.
image
collectionRefernce ~ text

• Delete Collection
Deleted collection.
image
collectionReference ~ text

• Delete Document
Deleted document.
image
documentReference ~ text

Events

• Got All Docs
Event returns all documents.
image
documents ~ list

• Got Query
Event returns a list with the selected data.
image
documents ~ list

• On Success
Returns the event if any method is successful.
image
message ~ text

• On Failure
Returns the error message.
image
message ~ text

• On Listener Added
When registering the listener, this event will be called when adding a field to the collection.
image
document ~ dictionary

• On Listener Modified
When registering the listener, this event will be called when modifying a field in the collection.
image
document ~ dictionary

• On Listener Removed
When registering the listener, this event will be called when removing a field from the collection.
image
document ~ dictionary

3.Downloads

Aix file: com.jdl.Firestore.aix (2,5,MB)

Aia file: Firestore.aia (2,5,MB)

4.Open Source

5.Credits

I thank @Aditya_Singh for the suggestion.

Thank you very much Kodular, for being part of my life :heart:

6.Donate

If you liked my work, donate me any amount so that I can remain motivated to create free and open source extensions.
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=QJ76K7BA7KD3A&currency_code=USD&source=url

48 Likes

Great extension man! :heart_eyes: Love your extensions.

A guide on this extension will be great, if someone make it.

Why the size of this extension is too large (2.5 Mb) ?

2 Likes

Great job. I appreciate your hard work! Keep it up :v:

I think this is the first extension in all app inventor platforms having the size of 2.5 MB :hushed:

1 Like

I think due to Firestore SDK.

2 Likes

Great Extension. Nice work

1 Like

That’s right, this size is due to all the dependencies included.

4 Likes

Nice, Extension :ok_hand:

To understand it.

1 Like

Nice & helpfull extention. But need some guide.we are new with this db

1 Like

Nice extension. Very useful. congratulations :pray:

1 Like

Follow this guide to help obtain keys.

Guide

I hope that in the future someone will do better.

9 Likes

Nice Extension. Thank you for creating this

1 Like

OMG u have created a series of unbelievable extensions thanku for this contribution to the community your doing something very special and unexpected :heart::heart::heart::heart::heart:

2 Likes

This looks great. I might even make use of it in the near future for a game I have published in the Play Store.

1 Like

Congratulations ! Another Incredible Extension! :+1:

1 Like

hello, I have been with kodular for a short time and your extension looks great, but I cannot test it, I did all the configuration, accepted the application to firebase, changed the rules, put the APIKEY, IDPROYECT and IDAPP, but it fails to add the 200 cities and don’t believe it the collection please help me I may be doing wrong

Are there any error messages?

Did you mean mobilesdk_app_id?

Check it if your block is configured in a similar way.

You shouldn’t share the API Key to everyone!!

1 Like

This is not my API Key. :grin:

1 Like

I was working on the same extension from last few days and I have to say that you’ve really done a great job, especially since you were able to keep the extension’s size so small. Congrats, @jarlissonlira2!

2 Likes

I managed to reduce the size using version 15, later versions had problems.
Thank you! I really admire your work, I use your Phase extension.

1 Like