Category: SQL

NestJS SQL

API with NestJS #115. Database migrations with Prisma

This entry is part 115 of 187 in the API with NestJS

One of the characteristics of relational databases is a strict data structure. We need to specify the shape of every table with its fields, indexes, and relationships. Even if we design our database carefully, the requirements that our application must meet are changing. Because of that, our database needs to evolve as well. When restructuring […]

NestJS SQL

API with NestJS #111. Constraints with PostgreSQL and Prisma

This entry is part 111 of 187 in the API with NestJS

One of the most important aspects of working with a database is ensuring the stored information is correct. One of the fundamental ways of doing that is by using the correct data types for the columns in our tables. Thanks to that, we can make sure that a particular column holds only numbers, for example. […]

NestJS SQL

API with NestJS #110. Managing JSON data with PostgreSQL and Prisma

This entry is part 110 of 187 in the API with NestJS

Relational databases such as PostgreSQL are great for storing structured data. This approach has many advantages, but it can lack flexibility. On the other hand, databases such as MongoDB that store JSON-like documents might give you more flexibility than you would like. Fortunately, PostgreSQL offers support for storing and querying loosely-structured JSON data. This article […]

NestJS SQL

API with NestJS #109. Arrays with PostgreSQL and Prisma

This entry is part 109 of 187 in the API with NestJS

PostgreSQL stands out as a feature-reach solution among other relational databases. Most of the column types available in PostgreSQL allow storing a single value. However, PostgreSQL, unlike most SQL databases, enables us to define columns as arrays. With them, we can store collections of values within a single column, reducing the need to create separate […]

NestJS SQL

API with NestJS #108. Date and time with Prisma and PostgreSQL

This entry is part 108 of 187 in the API with NestJS

Storing date and time in our database might be tricky, but it is essential to get it right. In this article, we tackle this issue using PostgreSQL and Prisma. We also learn the concept of timezones and how to deal with them when designing our database. How PostgreSQL interprets dates We can learn how our […]

NestJS SQL

API with NestJS #107. Offset and keyset pagination with Prisma

This entry is part 107 of 187 in the API with NestJS

The bigger our database, the more we need to care about the performance. Returning too much data at once through our API might not be the best approach when it comes to performance. A common solution is to divide our data into chunks and present it to the user as infinite scrolling or multiple pages. […]

NestJS SQL

API with NestJS #106. Improving performance through indexes with Prisma

This entry is part 106 of 187 in the API with NestJS

The bigger our database, the more we need to care about its performance. A common way of improving it is through indexes. Therefore, this article introduces the idea of indexes and implements them through Prisma. You can find the code from this article in this repository. Introduction to indexes In one of the recent articles, […]

NestJS SQL

API with NestJS #105. Implementing soft deletes with Prisma and middleware

This entry is part 105 of 187 in the API with NestJS

When developing our REST APIs, we often focus on implementing the four fundamental operations: creating, reading, updating, and deleting (CRUD). The most basic approach to removing a record from our database is to delete it permanently. In this article, we explore the idea of soft deletes that allow us to keep the removed entities in the database. […]

NestJS SQL

API with NestJS #90. Using various types of SQL joins

This entry is part 90 of 187 in the API with NestJS

It’s a very common case to need to combine multiple related tables. In SQL, we can do that using a join statement. Therefore, this article explains various types of joins along with real-life examples. Inner joins A few articles ago, we defined the  and tables.

It’s typical to retrieve a particular post along […]

JavaScript NestJS SQL

API with NestJS #88. Testing a project with raw SQL using integration tests

This entry is part 88 of 187 in the API with NestJS

Covering our project with tests can help us ensure that our application works as expected and is reliable. While unit tests play a significant role, they are not enough. Therefore, this article explains the significance of integration tests and implements them in a NestJS project that uses raw SQL queries. The significance of integration tests […]