Category: SQL

NestJS SQL

API with NestJS #176. Database migrations with the Drizzle ORM

This entry is part 176 of 177 in the API with NestJS

Relational databases are known for their strict data structures. Every table requires a defined schema, including columns, indexes, and relationships. Despite careful planning during database design, application requirements often evolve. As a result, the database must adapt to keep up with these new needs. However, it’s crucial to ensure that no existing data is lost […]

NestJS SQL

API with NestJS #174. Multiple PostgreSQL schemas with Drizzle ORM

This entry is part 174 of 177 in the API with NestJS

PostgreSQL uses schemas as namespaces within the database to hold tables and other structures, such as indexes. In this article, we explain how to use them with the Drizzle ORM and how they can be beneficial. The public schema Out of the box, PostgreSQL creates a schema called for each new database. database-schema.ts

[…]

NestJS SQL

API with NestJS #163. Full-text search with the Drizzle ORM and PostgreSQL

This entry is part 163 of 177 in the API with NestJS

With PostgreSQL’s full-text search feature, we can quickly find documents that contain a particular word or phrase. It can also sort the results to show the most relevant matches first. In this article, we learn how to implement it with the Drizzle ORM, PostgreSQL, and NestJS. Column types used with the text-search feature To implement […]

NestJS SQL

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

This entry is part 154 of 177 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 177 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 177 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 177 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 […]