Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
typeorm-dynamic-filters
Advanced tools
Readme
Create a TypeORM query builder for listing entries with filters, pagination and ordination.
run:
npm install typeorm-dynamic-filters
or
yarn add typeorm-dynamic-filters
This package is compatible with TypeORM 0.3 !
For a TypeORM 0.2 compatible version you should use 0.0.2 version by running:
npm install typeorm-dynamic-filters@0.0.2
You will need to import and instantiate the main class
import { getRepository } from 'typeorm';
import { FilterBuilder } from 'typeorm-dynamic-filters';
const myOrmRepository = getRepository<User>(User);
const filterQueryBuilder = new FilterBuilder(myOrmRepository, 'alias');
Then build the queryBuilder for our filters:
const queryFilter = {
filterBy: ['role'],
filterType: ['not'],
filterValue: ['admin'],
page: 1,
per_page: 12,
orderBy: 'id',
orderType: 'ASC',
};
const queryBuilder = filterQueryBuilder.build(queryFilter);
The queryFilter object must be an IFilterQuery object which may be parsed from an ExpressJS request query.
import { parseQueryFilters } from 'typeorm-dynamic-filters';
.
.
.
const filter = parseQueryFilters(request.query)
Example:
?filterBy=name&filterValue=Maria&filterType=like&page=1&per_page=15&orderBy=id&orderType=ASC
will return the object:
{
filterBy: ['name'],
filterType: ['like'],
filterValue: ['Maria'],
page: 1,
per_page: 15,
orderBy: 'id',
orderType: 'ASC',
}
You may use multiple filters in your query by splitting the fields by comma ','
?filterBy=name,role,active&filterValue=Maria,user,true&filterType=like,eq,eq
{
filterBy: ['name','role','active'],
filterType: ['like','eq','eq'],
filterValue: ['Maria','user','true'],
page: 1,
per_page: 15,
orderBy: 'id',
orderType: 'ASC',
}
The valid filter types are:
import {listWithFilterSchema} from 'typeorm-dynamic-filters';
If you find any bugs in the project please create an issue.
Copyright (c) 2022 Marcelo Kortkamp kortkamp.dev
FAQs
Create a TypeORM query builder for listing entries with filters, pagination and ordination.
The npm package typeorm-dynamic-filters receives a total of 52 weekly downloads. As such, typeorm-dynamic-filters popularity was classified as not popular.
We found that typeorm-dynamic-filters demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.