Skip to main content

Introduction

The RequestQueryBuilder class provides a fluent API for constructing complex query strings for NestJS CRUD operations. It supports filtering, sorting, pagination, field selection, and relation joining with a chainable, type-safe interface.

Installation

Basic Usage

Creating an Instance

There are two ways to create a RequestQueryBuilder instance:

Static Factory Method

Constructor

Create from Parameters

You can initialize a query builder with all parameters at once:

Key Features

Field Selection

Choose which fields to return in the response

Filtering

Filter records with various comparison operators

Sorting

Sort results by one or multiple fields

Pagination

Paginate results with limit/offset or page-based pagination

Relations

Join and select related entities

Search

Complex search with AND/OR conditions

Configuration

You can configure global options for all RequestQueryBuilder instances:
string
default:"||"
Delimiter used to separate parts of a query parameter (e.g., field||operator||value)
string
default:","
Delimiter used to separate array values (e.g., field1,field2,field3)
object
Map of parameter names used in the query string. Each key can be a string or array of strings.

Query Generation

After building your query, generate the query string:
When search() is used, it takes precedence over filter and or conditions. The filter and or parameters will be ignored in the final query string.

Advanced Examples

Complex Filtering with OR Conditions

Joining Relations

Search with Complex Conditions

Properties

object
The internal object representation of the query before it’s converted to a string
string
The generated query string (available after calling query())
RequestQueryBuilderOptions
The current configuration options for the builder

Next Steps

Methods Reference

Explore all available methods and their signatures

Operators Reference

Learn about all query operators and how to use them