From the course: Databases for Node.js Developers
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Loading and syncing the models - Node.js Tutorial
From the course: Databases for Node.js Developers
Loading and syncing the models
- [Instructor] So far, we actually have only created arbitrary functions that don't connect to the database yet. The infrastructure we will create now can be used in any framework to dynamically load and associate Sequelize models. In Fastify, to keep it modular, we will use a Fastify plugin for this again. This will ensure that models are initialized and the relationships are defined when the app starts. So let's get started. For that, I go back into my src, plugins and there databases and sequelize. Let's close the sidebar. We don't need it at this point. And up there, I will have to bring in a few more helpers now. I first import readdir from the Node internal "fs/promises." And I also bring in path, also a Node Core module for path operations on directories from "path". Then I scroll down and right after, we do all the operations for basically connecting to Sequelize. I will now add something new. Let's write deal with models. And there we'll first define an empty object for…
Contents
-
-
-
-
-
-
(Locked)
Using MySQL for our users and orders1m 8s
-
(Locked)
Setting up MySQL with Docker2m 49s
-
(Locked)
Exploring MySQL with MySQL Workbench1m 57s
-
(Locked)
Introducing Sequelize1m 51s
-
(Locked)
Setting up the database connection7m 43s
-
(Locked)
Designing the database structure2m 1s
-
(Locked)
Creating a user model for Sequelize7m 47s
-
(Locked)
Creating the order models for Sequelize11m 56s
-
(Locked)
Loading and syncing the models13m 5s
-
(Locked)
Creating, updating and deleting users with Sequelize12m 52s
-
(Locked)
Securing credentials with password hashing7m 2s
-
(Locked)
Implementing the user login9m 15s
-
(Locked)
-
-
-