QueryBuilder

TypeORM QueryBuilder is a powerful feature. We can use it to construct SQL queries programmatically with a chainable interface. Chainable means linking or connecting multiple functions or methods in a sequence. When constructing SQL queries with a chainable interface, each part of the query can be added sequentially, making it more flexible and readable.

QueryBuilder supports a variety of operations for selecting, filtering, sorting, and manipulating data within the database tables.

In this lesson, we’ll explore how this feature empowers us to construct complex and efficient database queries within our NestJS applications.

Select query

Repository API and entity manager are two ways to interact with the database. We can create the QueryBuilder with either one.

Repository API

Let’s convert the getById method to use QueryBuilder using repository API.

Get hands-on with 1200+ tech skills courses.