nestjs-query-mikro-orm
v0.0.7
Published
NestJS Query adapter for MikroORM
Maintainers
Readme
nestjs-query-mikro-orm
A NestJS Query adapter for MikroORM.
This library provides a seamless integration between NestJS Query and MikroORM, allowing you to build powerful GraphQL APIs with minimal boilerplate.
Features
- 🚀 Full NestJS Query support with MikroORM
- 📦 Type-safe query building
- 🔍 Advanced filtering and sorting
- 🔗 Relation query support
- 📊 Aggregation queries
- 🎯 Soft delete support
- ✨ Built with TypeScript
- 📦 Dual-format support (ESM & CommonJS)
Compatibility
This package supports both ES Modules (ESM) and CommonJS (CJS) for maximum compatibility across different Node.js environments and bundlers.
- ESM:
import { MikroOrmQueryService } from 'nestjs-query-mikro-orm' - CommonJS:
const { MikroOrmQueryService } = require('nestjs-query-mikro-orm')
The package automatically detects the import method and serves the appropriate format.
Installation
pnpm add nestjs-query-mikro-orm
# Install peer dependencies if you haven't already
pnpm add @mikro-orm/core @nestjs/common @nestjs/core @nestjs-query/core reflect-metadata rxjsQuick Start
1. Setup MikroORM Module
import { NestQueryMikroOrmModule } from 'nestjs-query-mikro-orm';
import { Module } from '@nestjs/common';
import { UserEntity } from './user.entity';
@Module({
imports: [NestQueryMikroOrmModule.forFeature([UserEntity])],
})
export class UserModule {}2. Create Your Entity
import { Entity, PrimaryKey, Property } from '@mikro-orm/core';
@Entity()
export class UserEntity {
@PrimaryKey()
id!: number;
@Property()
name!: string;
@Property()
email!: string;
@Property()
createdAt: Date = new Date();
}3. Use the Query Service
import { Injectable } from '@nestjs/common';
import { MikroOrmQueryService } from 'nestjs-query-mikro-orm';
import { UserEntity } from './user.entity';
@Injectable()
export class UserService extends MikroOrmQueryService<UserEntity> {
// Your custom methods here
}Development
Prerequisites
- Node.js >= 18
- pnpm >= 9
Setup
# Install dependencies
pnpm install
# Setup git hooks
pnpm prepareAvailable Scripts
# Build the library
pnpm build
# Build in watch mode
pnpm dev
# Run tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Run tests with coverage
pnpm test:coverage
# Lint code
pnpm lint
# Fix lint issues
pnpm lint:fix
# Format code
pnpm format
# Check formatting
pnpm format:check
# Type check
pnpm typecheckGit Hooks
This project uses Husky for git hooks:
- pre-commit: Runs lint-staged to format and lint staged files
- pre-push: Runs lint, typecheck, and tests before pushing
- commit-msg: Validates commit messages using commitlint
Commit Convention
This project follows Conventional Commits:
feat: add new feature
fix: fix bug
docs: update documentation
style: format code
refactor: refactor code
test: add tests
chore: update dependenciesLicense
MIT
Author
Manuel Antunes
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
