Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
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.
typeorm-cursor-pagination
Advanced tools
Readme
Cursor-based pagination works with TypeORM Query Builder.
Why or What is Cursor-Based Pagination
If this project is helpful to you, I truly appreciate you all for your stars ⭐⭐⭐ and contributions 💪💪💪.
npm install typeorm-cursor-pagination --save
import { getConnection } from "typeorm";
import { buildPaginator } from 'typeorm-cursor-pagination';
const queryBuilder = getConnection()
.getRepository(User)
.createQueryBuilder('user')
.where("user.gender = :gender", { gender: 'male' });
const paginator = buildPaginator({
entity: User,
paginationKeys: ['id'],
query: {
limit: 10,
order: 'ASC',
},
});
// Pass queryBuilder as parameter to get paginate result.
const { data, cursor } = await paginator.paginate(queryBuilder);
The buildPaginator
function has the following options
entity
[required]: TypeORM entity.alias
[optional]: alias of the query builder.paginationKeys
[optional]: array of the fields to be used for the pagination, default is id
.query
[optional]:
limit
: limit the number of records returned, default is 100.order
: ASC or DESC, default is DESC.beforeCursor
: the before cursor.afterCursor
: the after cursor.paginator.paginate(queryBuilder)
returns the entities and cursor for the next iteration
interface PagingResult<Entity> {
data: Entity[];
cursor: Cursor;
}
interface Cursor {
beforeCursor: string | null;
afterCursor: string | null;
}
afterCursor
const nextPaginator = buildPaginator({
entity: User,
paginationKeys: ['id'],
query: {
limit: 10,
order: 'ASC',
afterCursor: cursor.afterCursor,
},
});
const { data, cursor } = await nextPaginator.paginate(queryBuilder);
beforeCursor
const prevPaginator = buildPaginator({
entity: User,
paginationKeys: ['id'],
query: {
limit: 10,
order: 'ASC',
beforeCursor: cursor.beforeCursor,
},
});
const { data, cursor } = await prevPaginator.paginate(queryBuilder);
To start an integration test, run the following command:
npm run test:docker
All contributions are welcome, open a pull request or issue any time.
Commit your changes using a descriptive commit message that follows commit message conventions.
© Ben Hu (benjamin658), 2021-NOW
Released under the MIT License
FAQs
Cursor-based pagination works with TypeORM.
The npm package typeorm-cursor-pagination receives a total of 6,685 weekly downloads. As such, typeorm-cursor-pagination popularity was classified as popular.
We found that typeorm-cursor-pagination 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.
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.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.