Search⌘ K
AI Features

Developing the Data Accessing Logic

Explore how to build the data access layer of a Deno web application by implementing a repository class with TypeScript. Understand how to abstract data storage with an ES6 Map, create asynchronous methods to retrieve records, and organize imports for scalable architecture. This lesson prepares you to connect business logic with data management effectively.

Define the types

We need a database or something that looks like one to transform what we wrote previously into a fully functioning app. We need something that can store and retrieve a list of museums. Let’s create that now.

While developing the controller, we noticed that we needed something that would be able to get the data, that is, the repository. This module will abstract all the calls to a data source, such as the data source that stores the museums. It will have a very well-defined set of methods, and whoever wants to access the data should do so through this module.

We already have part of its interface defined inside src/museums/types.ts, so let’s write a class that implements it. For now, we won’t connect it to a real database. We will use an ES6 Map as an in-memory database instead.

Steps for developing data access logic

Let’s ...