Firestore
See how to use the firestore database preset
You will need to have a Firestore database to use this preset! If you want to create one in the cloud for free, follow this guide
Env
The environment variables validation scheme receives a new property, now it is necessary to define the file path of your firebase account in the FIREBASE_PATH
variable:
Veja um exemplo do arquivo firebase.json
do banco de dados Firestore:
Below, check out the presets according to the library used:
Typesaurus
Estrutura
The structure of this template was made using the typesaurs library, so to create our data we used typesaurus schemas
The index.ts
file in the src/database
folder must connect to the database:
Document collections are stored in the db
variable object, that is, for each new document schema you create, place the collection as a property of this variable or as a sub-property of an existing one.
So when you need to create, read, update or delete data, just import the db
variable from #database
and use the collection methods:
Check the library documentation for best usage: https://typesaurus.com/get-started/
Always use the db
variable from the "#database"
import shortcut, this way the file containing the code that makes the connection to the database is called.
Interfaces
To have autocomplete of properties in the db variable when creating collections, it is necessary to pass data interfaces in the generic collections, you can create the interfaces of your collections in the src/databases/documents
folder
After creating your interface, import it into the index.ts
file in the src/database
folder and create a collection passing it as generic: