paginator-rs
A comprehensive, modular Rust pagination library with support for multiple databases and web frameworks. Built for production use with a focus on ergonomics, performance, and maintainability.
โจ Features
Core Features
- ๐ฏ Flexible Pagination: Page-based and offset/limit pagination
- ๐ง Builder Pattern: Fluent API for constructing pagination parameters
- ๐ Rich Metadata: Automatic calculation of total pages, has_next, has_prev
- ๐จ Sorting Support: Multi-field sorting with ascending/descending order
- โ ๏ธ Error Handling: Comprehensive error types with helpful messages
- ๐ JSON Serialization: Built-in serde support
Database Integrations
- SQLx (
paginator-sqlx): PostgreSQL, MySQL, SQLite support - SeaORM (
paginator-sea-orm): Type-safe ORM pagination with entity support - SurrealDB (
paginator-surrealdb): Multi-model database with SQL-like queries
Web Framework Integrations
- Axum (
paginator-axum): Query extractors and JSON responses with headers - Rocket (
paginator-rocket): Request guards and responders - Actix-web (
paginator-actix): Extractors, responders, and middleware
๐งฑ Workspace Structure
paginator-rs/
โโโ paginator-rs/ # Core trait and types
โโโ paginator-utils/ # Shared types (params, response, metadata)
โโโ paginator-sqlx/ # SQLx database integration
โโโ paginator-sea-orm/ # SeaORM integration
โโโ paginator-surrealdb/ # SurrealDB integration
โโโ paginator-axum/ # Axum web framework integration
โโโ paginator-rocket/ # Rocket web framework integration
โโโ paginator-actix/ # Actix-web integration
โโโ paginator-examples/ # Usage examples
๐ฆ Installation
Core Library
[]
= "0.1.2"
= "0.1.2"
= { = "1", = ["derive"] }
With SQLx (PostgreSQL)
[]
= { = "0.1", = ["postgres", "runtime-tokio"] }
= { = "0.8", = ["postgres", "runtime-tokio"] }
With SeaORM
[]
= { = "0.1", = ["sqlx-postgres", "runtime-tokio"] }
= { = "1.1", = ["sqlx-postgres", "runtime-tokio"] }
With SurrealDB
[]
= { = "0.1", = ["protocol-ws", "kv-mem"] }
= { = "2.1", = ["protocol-ws", "kv-mem"] }
With Axum
[]
= "0.1"
= "0.7"
With Rocket
[]
= "0.1"
= { = "0.5", = ["json"] }
With Actix-web
[]
= "0.1"
= "4"
๐ Usage Examples
Basic Pagination
use ;
use ;
// Using builder pattern
let params = new
.page
.per_page
.sort_by
.sort_asc
.build;
// Or create directly
let params = new;
Filtering & Search
use ;
// Example 1: Simple filtering
let params = new
.page
.per_page
.filter_eq
.filter_gt
.build;
// Example 2: Advanced filtering with multiple operators
let params = new
.filter_in
.filter_between
.build;
// Example 3: Full-text search
let params = new
.search
.build;
// Example 4: Combined filters and search
let params = new
.page
.per_page
.filter_eq
.filter_gt
.search
.sort_by
.sort_desc
.build;
// Get generated SQL WHERE clause
if let Some = params.to_sql_where
Available Filter Operators:
filter_eq(field, value)- Equal (=)filter_ne(field, value)- Not equal (!=)filter_gt(field, value)- Greater than (>)filter_lt(field, value)- Less than (<)filter_gte(field, value)- Greater than or equal (>=)filter_lte(field, value)- Less than or equal (<=)filter_like(field, pattern)- SQL LIKE pattern matchingfilter_ilike(field, pattern)- Case-insensitive LIKEfilter_in(field, values)- IN arrayfilter_between(field, min, max)- BETWEEN min AND maxfilter_is_null(field)- IS NULLfilter_is_not_null(field)- IS NOT NULL
Search Options:
search(query, fields)- Case-insensitive fuzzy searchsearch_exact(query, fields)- Exact match searchsearch_case_sensitive(query, fields)- Case-sensitive search
With Axum
use ;
use ;
use Serialize;
async
let app = new.route;
With SQLx (PostgreSQL)
use paginate_query;
use PaginatorBuilder;
use PgPool;
async
With SeaORM
use PaginateSeaOrm;
use PaginationParams;
use ;
async
With SurrealDB
use Surreal;
use Ws;
use ;
use PaginatorBuilder;
async
With Rocket
use ;
use ;
async
With Actix-web
use ;
use ;
async
๐งช Response Format
HTTP Headers (Web Framework Integrations)
X-Total-Count: 100
X-Total-Pages: 5
X-Current-Page: 1
X-Per-Page: 20
๐ฏ Query Parameters
Basic Pagination & Sorting
GET /api/users?page=2&per_page=20&sort_by=name&sort_direction=asc
page: Page number (1-indexed, default: 1)per_page: Items per page (default: 20, max: 100)sort_by: Field to sort by (optional)sort_direction:ascordesc(optional)
With Filters
GET /api/users?page=1&filter=status:eq:active&filter=age:gt:18&filter=role:in:admin,moderator
filter: Filter in formatfield:operator:value- Multiple filters can be combined (AND logic)
Filter Format Examples:
status:eq:active- Equalage:gt:18- Greater thanage:between:18,65- Betweenrole:in:admin,moderator,user- In arrayname:like:%john%- LIKE patterndeleted_at:is_null- IS NULL
With Search
GET /api/users?search=john&search_fields=name,email,bio
search: Search query textsearch_fields: Comma-separated list of fields to search in
Combined Example
GET /api/users?page=1&per_page=10&filter=status:eq:active&filter=age:gt:18&search=developer&search_fields=title,bio&sort_by=created_at&sort_direction=desc
๐ง Builder Pattern
use PaginatorBuilder;
let params = new
.page
.per_page
.sort_by
.sort_desc
.build;
โ ๏ธ Error Handling
use ;
// Errors are comprehensive and helpful
match result
๐๏ธ Architecture
- Easy to Use: Builder pattern and sensible defaults
- Easy to Debug: Comprehensive error messages and type safety
- Easy to Maintain: Modular crate structure with clear separation of concerns
๐ Examples
Run the examples:
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
MIT ยฉ 2025 Maulana Sodiqin
๐ Links
- Repository
- Documentation (coming soon)
- crates.io (coming soon)