Actions Overview
Cloud actions make it simple to define a set of database operations with consistent names and parameters. They also provide type safety to common actions like creating or updadating a document.
Goals
- 👩💻 Managing documents should be a great developer experience with simple implementations and TypeScript hints and warnings.
- 🔒 Data should be structured so that it’s easy to secure, but we shouldn’t have to constantly constuct long paths to the data we wish to manage.
- 🔎 Metadata like the date a post was created should be managed in the database for easy sorting and querying.
Implementation
The action utilities provided by @firebridge/cloud
make it easy to create your own simple actions for performing database operations. For example:
We provide utilities for all of the common database operations. You can select one below to learn more:
firestoreAdd
for adding documentsfirestoreDelete
for deleting documentsfirestoreGet
for reading documentsfirestoreSet
for setting documentsfirestoreUpdate
for updating documentsfirestoreMerge
for merging documents
Purpose
The purpose of our cloud actions is to enable a cleaner and more consistent developer experience when working with the database. They allow you to easily wrap Firestore’s already simple API with some additional functionality.
Adding Data
Let’s say we have a blog app where users can create posts. What is the simplest function we could provide developers to add a post to the database?
Nice and simple, and it’s typesafe too! We’ll get a warning if we try to add a post without a title, or if we try to add a post with a property that doesn’t exist.
Now, let’s add a comment to our post. You can already imagine how this might work from the example above.
Reading Data
Next, let’s say we want to read a single post or comment. We should be able to do this with a single function call.
If we want to perform more complex queries, we should be able to do that too using the standard calls provided by the Firestore Admin SDK. In this case, let’s query some of the metadata our functions automatically added to our documents.
Deleting Data
Finally, we should be able to delete a post with a single function call. Since posts have subcollections and child documents, we should automatically delete those too.