Category: TypeScript

NestJS

API with NestJS #158. Soft deletes with the Drizzle ORM

This entry is part 158 of 158 in the API with NestJS

Deleting entities is a standard feature in most REST APIs. The most straightforward approach is to remove rows from the database permanently. However, we can use soft deletes to keep the deleted entities in our database. In this article, we learn how to do it using the Drizzle ORM and PostgreSQL. Introducing soft deletes To […]

NestJS

API with NestJS #157. Handling JSON data with PostgreSQL and the Drizzle ORM

This entry is part 157 of 158 in the API with NestJS

PostgreSQL is well-suited for handling structured data and keeping everything organized and consistent. On the other hand, MongoDB stores data in flexible JSON-like documents, making it ideal for data with varying attributes and changing requirements. While SQL databases have many advantages, there are times when flexibility is needed. Fortunately, PostgreSQL bridges this gap by allowing […]

NestJS

API with NestJS #156. Arrays with PostgreSQL and the Drizzle ORM

This entry is part 156 of 158 in the API with NestJS

Thanks to some of its features, PostgreSQL sets itself apart from other SQL databases. Unlike many SQL databases that limit columns to single entries, PostgreSQL lets us store multiple values in a single column. This simplifies database design and can improve performance. In this article, we will explore the practical uses of arrays in PostgreSQL […]

NestJS

API with NestJS #155. Offset and keyset pagination with the Drizzle ORM

This entry is part 155 of 158 in the API with NestJS

As our database grows, maintaining good performance becomes more important. Returning large amounts of data at once through our API can negatively affect efficiency. A common solution is to divide data into smaller chunks, presenting it to the user as infinite scrolling or multiple pages. In this article, we implement this approach using PostgreSQL and […]

NestJS SQL

API with NestJS #154. Many-to-many relationships with Drizzle ORM and PostgreSQL

This entry is part 154 of 158 in the API with NestJS

Creating relationships across tables is a crucial aspect of working with SQL databases. Previously, this series focused on using the Drizzle ORM to create simple relationships, such as one-to-one and many-to-one relationships. In this article, we learn about many-to-many relationships, which are slightly more complex. Introducing many-to-many relationships A many-to-many relationship is necessary when multiple […]

NestJS SQL

API with NestJS #153. SQL transactions with the Drizzle ORM

This entry is part 153 of 158 in the API with NestJS

Ensuring the integrity of the data is a fundamental responsibility of each developer. Fortunately, SQL databases give us the tools to ensure our database stays consistent and accurate. A crucial scenario to consider is when two SQL queries depend on each other. A typical example is transferring money between two bank accounts. Suppose we have […]

NestJS SQL

API with NestJS #152. SQL constraints with the Drizzle ORM

This entry is part 152 of 158 in the API with NestJS

When working with SQL databases, we can configure constraints to ensure our data does not get corrupted. In this article, we explore and implement different SQL constraints using PostgreSQL, NestJS, and the Drizzle ORM. Not-null constraint By default, SQL columns can hold nulls, representing an absence of value. We need the not-null constraint using the […]

NestJS SQL

API with NestJS #151. Implementing many-to-one relationships with Drizzle ORM

This entry is part 151 of 158 in the API with NestJS

Managing relationships between tables is a significant part of dealing with SQL databases. In this article, we continue learning to use Drizzle ORM with NestJS and implement many-to-one relationships. Check out this repository if you want to see the full code from this article. The many-to-one relationship With many-to-one relationships, a row from the first […]

NestJS SQL

API with NestJS #150. One-to-one relationships with the Drizzle ORM

This entry is part 150 of 158 in the API with NestJS

When building a database, the tables we set up often connect to each other. Managing these relationships is one of the crucial parts of working with databases. In the previous article, we learned how to use NestJS with Drizzle to set up a simple project with PostgreSQL. This time, we go further and write more […]