Fresh + Deno + Firebase: Firestore Scalable NoSQL Database
Data is the primary object in modern development, where users are, data thrives. From capturing visits to updating carts, data is the medium of exchange in the information age.
Finding an exciting experience in building with Fresh and Deno, the next logical question was how to emit, record, and update data. Along with analytics for understanding traffic, accounting for views, and creating interface elements was an additional consideration.
Persisting & Storing Data in Cloud Firestore
Deno has documentation on various databases that fit the often referenced JAMStack, a fast and secure stack to deploy websites.
Persist data using Firebase
Firebase is a platform developed by Google for creating mobile and web applications. You can persist data on the…
A challenge with Deno and SQL currently is the need to connect to most Cloud providers’ SQL databases with an SSL connection, there are still few options for passing this with the configuration.
The first step in this process is creating a Firebase account, it is through this service, that Firestore becomes accessible. Once a project and configuration are provisioned, Firestore can be instantiated within Deno.
Deno added stable support for NPM packages in version 1.28 — with this update, importing modules with a named import is possible. Extending the configurability of Deno to build upon the thriving NPM ecosystem and further advance Deno applications. There is no `npm install`, simply dependencies delivered over the internet, available at compile time.
Deno 1.28: Featuring 1.3 Million New Modules
Deno 1.28 ships with stabilized npm modules, auto-discovered lock file, a new subprocess API, and more
If there is an issue with Deno Deploy and the imported modules, Skypack offers the ability to leverage ES Modules from NPM packages via CDN for use within Deno and many other cloud applications.
Cloud Firestore Methods for Queries
On the Firestore instance, specifically documented query methods can be used to implement CRUD (Create, Read, Update, and Delete) functionality for applications.
Perform simple and compound queries in Cloud Firestore | Firebase
Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a…
From these methods, `doc`, `getDoc`, and `updateDoc` can be used to read and write from Cloud Firestore which operates similarly to most NoSQL database solutions with collections of documents.
Implementing `doc` to instantiate the document constructor, `getDoc` can then be called with a configuration to request the document from Cloud Firestore.
Once the object and its structure is read and updated, the completed object can be updated in place within Cloud Firestore. Once again call the `doc` constructor, then `updateDoc` to store the updated object.
Accessing Firestore Data from Fresh
Preact Hooks `useState` and `useEffect` can be implemented, to request and implement the data persisted from Firestore, through Deno, to Fresh.
Extracting the collection document as or into an object can allow for passing an object or multiple objects to an iterator like `map` or `forEach` for dynamic frontend components.
Expounding upon this implementation can create very intricate and dynamic applications that solve thousands of use cases, all with performant, edge-based deployment.