Sequelize Adapter
Relevant source files
The following files were used as context for generating this wiki page:
The Sequelize Adapter, implemented in the @ptc-org/nestjs-query-sequelize package, provides a persistence layer for nestjs-query using the Sequelize ORM. It implements the QueryService interface defined in the core library, allowing developers to perform CRUD operations, sorting, and paging against relational databases. This adapter integrates with NestJS to provide automated GraphQL resolver functionality when combined with the GraphQL package.
Sources: packages/query-sequelize/package.json:3-5, README.md:27-28, packages/query-sequelize/README.md:14-16
Architecture and Integration
The Sequelize Adapter acts as a bridge between the framework-independent @ptc-org/nestjs-query-core and the Sequelize ORM. It utilizes sequelize-typescript for model definitions and @nestjs/sequelize for NestJS dependency injection. The adapter resides within the packages/ directory of the monorepo and is designed for use in both standalone services and GraphQL-based applications.
Sources: AGENTS.md:6-8, packages/query-sequelize/package.json:23-28
Dependency Structure
The following diagram illustrates how the Sequelize adapter depends on core libraries and external ORM tools.
The diagram shows the relationship between the Sequelize adapter, the project core, and the underlying Sequelize ecosystem.
Sources: packages/query-sequelize/package.json:22-28, README.md:21-31
Core Components
The adapter's primary component is the SequelizeQueryService. This service translates nestjs-query filter objects, paging parameters, and sorting definitions into Sequelize-compatible queries. It supports standard relational database operations and provides hooks for customizing data access logic.
Sources: packages/query-sequelize/README.md:14-16, documentation/sidebars.js:33-35
Key Classes and Modules
| Component | Description |
|---|---|
SequelizeQueryService | Implements the core QueryService interface using Sequelize models. |
NestjsQuerySequelizeModule | NestJS module used to register Sequelize entities for use with query services. |
Sequelize-Typescript Models | User-defined classes decorated to represent database tables. |
Sources: packages/query-sequelize/package.json:26-28, documentation/sidebars.js:33-35, README.md:27-28
Data Flow
Data flows from the user (via GraphQL or REST) through the resolver, into the SequelizeQueryService, which then interacts with the database through the Sequelize ORM.
The sequence diagram details the path of a read request from a client to the relational database using the adapter.
Sources: README.md:14-17, AGENTS.md:28-32, packages/query-sequelize/README.md:14-16
Configuration and Usage
To use the adapter, you must register the specific Sequelize entities within a NestJS module. This registration allows the internal dependency injection system to provide the necessary models to the query services.
Installation and Peer Dependencies
The package requires specific peer dependencies to function within a NestJS environment.
| Package | Version Requirement |
|---|---|
@nestjs/common | ^10.0.0 or ^11.0.0 |
@nestjs/sequelize | ^10.0.0 or ^11.0.0 |
sequelize | ^6.5.0 |
sequelize-typescript | ^1.1.0 or ^2.0.0 |
Sources: packages/query-sequelize/package.json:22-28
Summary
The Sequelize Adapter provides a robust implementation of the nestjs-query interface for relational databases. By leveraging Sequelize, it allows developers to build scalable GraphQL APIs with minimal boilerplate code for common database operations like filtering, sorting, and pagination. It is a core part of the nestjs-query ecosystem, ensuring compatibility with standard relational data persistence patterns.
Sources: README.md:27-28, packages/query-sequelize/README.md:14-16, AGENTS.md:28-32