Implement the Data Access Layer
Layered Architecture·2 min read·Jan 1, 2025
The Data Access Layer is the layer responsible for performing input/output operations outside of the application's boundaries, such as communicating with the database.
One of the easiest ways to implement this layer is to use an Object-Relational Mapper (ORM), such as Sequelize, to create an object that exposes generic handlers for performing CRUD operations on the database, acting as an intermediary between the Service Layer and the database instance.
Setting up the MySQL database
Assuming we're using MySQL, we have to first set it up by creating a new database for the application at hand, a new database table to store user's information, and a new database user with limited privileges to administer this table.
Creating a new database
Let's start by connecting to the MySQL server using the root account, or any other account with sufficient privileges to create databases and users:
$ mysql -u root -pOnce logged in, let's create a new database named app:
mysql> CREATE DATABASE app;And let's switch to that database:
mysql> USE app;Creating a new table
Within the app database, let's create a new table named users:
mysql> CREATE TABLE users ( -> id INT AUTO_INCREMENT NOT NULL PRIMARY KEY, -> email VARCHAR(320) NOT NULL UNIQUE,Unlock the program 🚀
Pay once, own it forever.
€79
30-day money-back guarantee
- 13 modules
- 113 lessons with full-code examples
- 29 projects with commented solutions
- All future lesson and project updates
- Lifetime access
By submitting this form, you agree to the Terms & Conditions and Privacy Policy.