Book Image

Nest.js: A Progressive Node.js Framework

By : Greg Magolan, Patrick Housley, Adrien de Peretti, Jay Bell, David Guijarro
Book Image

Nest.js: A Progressive Node.js Framework

By: Greg Magolan, Patrick Housley, Adrien de Peretti, Jay Bell, David Guijarro

Overview of this book

Nest.js is a modern web framework built on a Node.js Express server. With the knowledge of how to use this framework, you can give your applications an organized codebase and a well-defined structure. The book begins by showing how to use Nest.js controllers, providers, modules, bootstrapping, and middleware in your applications. You’ll learn to use the authentication feature of Node.js to manage the restriction access in your application, and how to leverage the Dependency Injection pattern to speed up your application development. As you advance through the book, you'll also see how Nest.js uses TypeORM—an Object Relational Mapping (ORM) that works with several relational databases. You’ll use Nest.js microservices to extract part of your application’s business logic and execute it within a separate Nest.js context. Toward the end of the book, you’ll learn to write tests (both unit tests as well as end-to-end ones) and how to check the percentage of the code your tests cover. By the end of this book, you’ll have all the knowledge you need to build your own Nest.js applications.
Table of Contents (16 chapters)

Chapter 6. Sequelize

Sequelize is a promise-based ORM working for Node.js v4 and later. This ORM supports many dialects, such as:

  • PostgreSQL
  • MySQL
  • SQLite
  • MSSQL

This provides a solid support for transactions. With Sequelize you have the possibility of using sequelize-typescript, which provides decorators to put in your entity and manages all the fields of your model, with types and constraints.

Also, Sequelize comes from many hooks providing you with the significant advantage of being able to check and manipulate your data at any level of the transaction.

In this chapter, we will see how to configure your database using postgresql and how to configure the connection to your database. After that we will see how to implement our first entity, which will be a simple User entity and then how to create a provider for this entity in order to inject the entity into a UserService. We will also see the migration system through umzung, and how to create our first migration file.

You can have...