JavaScript NestJS

API with NestJS #112. Serializing the response with Prisma

This entry is part 112 of 121 in the API with NestJS

When fetching data from the database, we do not always want to present it to the user in the original form. When working with NestJS, the most popular way of modifying the response is with the library. However, using the above library with Prisma requires a bit of work. In this article, we provide […]

NestJS SQL

API with NestJS #111. Constraints with PostgreSQL and Prisma

This entry is part 111 of 121 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 121 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 121 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 121 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 121 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 121 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 121 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

API with NestJS #104. Writing transactions with Prisma

This entry is part 104 of 121 in the API with NestJS

As web developers, one of our primary concerns is keeping the integrity of our data. Fortunately, SQL databases come equipped with tools that allow us to ensure data accuracy and consistency. You can find the code from this article in this repository. One of the most fundamental examples of when things might go wrong is […]

NestJS

API with NestJS #103. Integration tests with Prisma

This entry is part 103 of 121 in the API with NestJS

In the previous part of this series, we learned how to write unit tests in a NestJS project with Prisma. Unit tests help verify if individual components of our system work as expected on their own. However, while useful, they don’t guarantee that our API functions correctly as a whole. In this article, we deal […]