Category: SQL

NestJS SQL

API with NestJS #65. Implementing soft deletes using MikroORM and filters

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

In this article, we look into the filters feature and implement soft deletes. With them, we can mark an entity as deleted without removing it from the database permanently. You can get the code from this article in this repository. Introducing MikroORM filters We can provide various filters when querying data using functions such as […]

NestJS SQL

API with NestJS #64. Transactions with PostgreSQL and MikroORM

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

One of the most important things to care about as a web developer is the integrity of the data. In this article, we learn what a transaction is and how it can help us ensure that our data is correct. The idea behind transactions A transaction is a set of instructions that either happens entirely […]

NestJS SQL

API with NestJS #63. Relationships with PostgreSQL and MikroORM

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

A significant advantage of SQL databases is handling relationships between various tables. Since, in web applications, entities often relate to each other, designing relationships is a big part of working with SQL databases. In this article, we continue learning MikroORM and use it to form relationships. You can find the code from this article in […]

Node.js SQL

Serial type versus identity columns in PostgreSQL and TypeORM

So far on this blog, we’ve used the serial type to define autoincrementing ids for our tables. However, TypeORM started fully supporting identity columns very recently. Since PostgreSQL official recommends using them, it is a good moment to go through both approaches and compare them. Serial type The serial data type allows us to generate unique […]

SQL

Creating views with PostgreSQL and TypeORM

In PostgreSQL, views act as virtual tables. Although they have rows and columns, we can’t insert any data into them manually. Instead, PostgreSQL runs an underlying query when we refer to the view. Creating views with PostgreSQL Let’s create a table of users to use it in a view.

Now, let’s define a view […]

SQL

Defining generated columns with PostgreSQL and TypeORM

On this blog, we’ve covered a variety of different column types. So far, we’ve performed various operations on said columns such as and to modify the data directly. In this article, we cover generated columns that work differently. Generated columns in PostgreSQL We call the above columns generated because PostgreSQL automatically computes their data based […]

SQL

The basics of database normalization with TypeORM and PostgreSQL

Database normalization is a term often used when discussing database architecture design. Unfortunately, it is often presented with the use of complex definitions that make it difficult to grasp. In this article, we explain what normalization is and provide examples using TypeORM and PostgreSQL. Database normalization aims to improve the integrity and reduce the redundancy […]

JavaScript NestJS SQL TypeScript

API with NestJS #53. Implementing soft deletes with PostgreSQL and TypeORM

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

In this series, we’ve implemented deleting functionalities for various entities. So far, it has always meant removing records permanently from our database. Instead, we can perform soft deletes. When we delete a record using a soft delete, we only mark it as deleted. You can find the code from this series in this repository. Soft […]

JavaScript SQL

Defining constraints with PostgreSQL and TypeORM

An important part of designing a database is controlling the data we store inside. The most fundamental way of doing that is defining the types for our columns. With that, we can make sure that a particular column holds only text, for example. In this article, we use constraints to have even more control of […]