Keyset pagination library made for nestjs(mongoose) by hungreebee technologies
Use the package manager npm to install Nestjs-Keyset-Paginator.
npm i nestjs-keyset-paginator
import { PaginationDto, projectionDto } from 'nestjs-keyset-paginator'
@Controller('example')
export class ExampleController {
constructor(private readonly exampleService: ExampleService) {
}
@Get()
findAll(@Body() params: PaginationDto) {
return this.exampleService.findAll(
params.skip,
params.limit,
params?.start_key,
params?.sort?.field,
params?.sort?.order,
params?.filter,
params?.projection
)
}
}
import paginate, { filterDto, projectionDto } from 'nestjs-keyset-paginator'
@Injectable()
export class ExampleService {
constructor(
@Inject(EXAMPLE_MODEL)
private readonly exampleModel: Model<ExampleDocument>
) {
}
async findAll(
skip = 0,
limit = 10,
start_key?,
sort_field?: string,
sort_order?: number,
filter?: filterDto[],
projection?: projectionDto[]
) {
return paginate(this.exampleModel, skip, limit, start_key, sort_field, sort_order, filter, projection)
}
}
{ docs: docs, next_key }
Example:-
{
"filter": [
{
"name": "score",
"value": 400,
"operator": "lt"
},
{
"name": "isPassed",
"value": true,
"operator": "eq"
},
{
"name": ["outer_field_name", "inner_field_name"],
"value": "user one",
"operator": "eq"
},
{
"name": "time",
"arr_value": [40, 60],
"operator": "in"
},
{
"name": "left_count",
"arr_value": [0, 1],
"operator": "nin"
}
],
"sort": {
"field": "score",
"order": 1
},
"projection": [
{
"name": "password",
"mode": 0
}
],
"limit": 4
}
Example:
{
"next_key": [
{
"key": "_id",
"value": "61a4c444f9534392c70afaf6"
},
{
"key": "score",
"value": 100
}
]
}
Example:
{
"filter": [
{
"name": "score",
"value": 400,
"operator": "lt"
},
{
"name": "isPassed",
"value": true,
"operator": "eq"
}
],
"sort": {
"field": "score",
"order": 1
},
"limit": 4,
"start_key": [
{
"key": "_id",
"value": "61a4c444f9534392c70afaf6"
},
{
"key": "score",
"value": 100
}
]
}
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate (if applicable).
Generated using TypeDoc