npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

typeorm-dynamic-search

v1.2.5

Published

Dynamic search service for NestJS and TypeORM

Readme

🚀 NestJS Dynamic Search

What is it?

nestjs-dynamic-search is a flexible and powerful search service package developed for NestJS and TypeORM. It allows you to dynamically create, filter, sort, and paginate your database queries.

✨ Features

  • 🔍 Dynamic and flexible filtering
  • 📄 Pagination support
  • 🔗 Multiple relation management
  • 🔢 Array and Enum type searching
  • 🌳 Tree structure querying
  • 🔄 Customizable sorting
  • 🚀 High performance
  • 💡 Easy to use

📦 Installation

npm install nestjs-dynamic-search
# or
yarn add nestjs-dynamic-search

🛠️ Usage Examples

Basic Usage

import { BaseService } from 'nestjs-dynamic-search';
import { WhereType, OrderType } from 'nestjs-dynamic-search';

@Injectable()
export class UserService extends BaseService<User> {
  constructor(
    @InjectRepository(User)
    private userRepository: Repository<User>
  ) {
    super(userRepository);
  }

  async findUsers() {
    const options = {
      query: { 
        name: 'John',  // Users with name John
        age: [25, 30]  // Users who are 25 or 30 years old
      },
      relations: ['role'], // Also include role information
      whereType: WhereType.AND,
      partialMatch: true,
      page: 1,
      take: 10,
      sort: 'name', // Sort by name
      order: OrderType.ASC // Ascending order
    };

    return this.searchPagination(options);
  }
}

Advanced Filtering

const complexOptions = {
  query: {
    name: 'John',         // Names containing John
    status: 'active',     // Active status
    age: [25, 30],        // 25 or 30 years old
    role: 1               // Specific role
  },
  relations: ['role', 'permissions'],
  whereType: WhereType.AND,
  order: OrderType.DESC,
  sort: 'updatedAt',      // Sort by update date
  partialMatch: true
};

const results = await userService.search(complexOptions);

Custom Sorting Usage

// Sort users by age in ascending order
const sortByAgeOptions = {
  query: { status: 'active' },
  sort: 'age',            // Sort by age
  order: OrderType.ASC,   // Ascending order
  take: 20
};

const youngToOldUsers = await userService.search(sortByAgeOptions);

// Sort users by creation date in descending order
const sortByCreatedAtOptions = {
  query: { status: 'active' },
  sort: 'createdAt',      // Sort by creation date
  order: OrderType.DESC,  // Descending order (newest to oldest)
  take: 20
};

const newestUsers = await userService.search(sortByCreatedAtOptions);

🔧 Parameters

SearchOptions

| Parameter | Type | Description | Default | |-----------|------|-------------|---------| | relations | string[] | Joins related tables | - | | whereType | WhereType | Query conditions connection (AND/OR) | AND | | order | OrderType | Sort direction (ASC/DESC) | DESC | | sort | string | Field name to sort by | createdAt | | query | object | Search criteria | - | | single | boolean | Returns a single result | false | | withDeleted | boolean | Includes deleted records | false | | take | number | Number of records to retrieve | - | | partialMatch | boolean | Partial text matching | false | | tree | string | Retrieves related data in tree structure | - |

🌈 Supported Features

  • Dynamic relationship management
  • Flexible AND/OR filtering
  • Partial text search
  • Array and Enum type searching
  • Customizable field sorting
  • Pagination
  • Include deleted records

⚠️ Important Considerations

  • Use relationship names in the relations parameter
  • Choose column names carefully in the query object
  • Avoid unnecessary relationships for performance
  • Ensure a valid column name is used in the sort parameter

🔒 License

MIT

🤝 Contributing

Bug reports and pull requests are always welcome. If you'd like to contribute, please open an issue first.

📞 Contact

For any issues or suggestions, please use GitHub issues.

Note: This package is designed to work with TypeORM and NestJS. Make sure you have completed the basic installation and configuration of these libraries before using it.