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.

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.

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.

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

Combining Oak HTTP for REST methods from the Deno backend and Axiod for HTTP requests from the Fresh frontend, Firestore can create document based object models.

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.

Thanks for Reading, Keep Storing!

Looking for more Application Development advice? Follow along on Twitter, GitHub, and LinkedIn. Visit online for the latest updates, news, and information at collectedview.io.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Joe Alongi

Joe Alongi

80 Followers

Application Developer @IBM — JavaScript, Java, Kubernetes, and Cloud Native. (These Views Are My Own) collectedview.io