Category: SQL

SQL

API with NestJS #121. Many-to-one relationships with PostgreSQL and Kysely

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

Designing relationships is one of the crucial aspects of working with SQL databases. In this article, we continue using Kysely with NestJS and implement many-to-one relationships. Check out this repository if you want to see the full code from this article. Introducing the many-to-one relationship When implementing the many-to-one relationship, a row from the first table […]

NestJS SQL

API with NestJS #119. Type-safe SQL queries with Kysely and PostgreSQL

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

Object-Relational Mapping (ORM) libraries such as Prisma and TypeORM can help us produce code faster by avoiding writing SQL queries. They have a smaller learning curve because we don’t need to learn a new language and dive deep into understanding how the database works. Unfortunately, ORM libraries often generate SQL queries that are far from […]

NestJS SQL

API with NestJS #115. Database migrations with Prisma

This entry is part 115 of 121 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 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, […]