Registry / database / egg-mysql-paginator

egg-mysql-paginator

JSON →
library1.0.1jsnpmunverified

MySQL paginator plugin for Egg.js framework (v1.0.1, last updated 2020). Adds a mysqlPaginator instance to the Egg application context, providing paginated MySQL queries with automatic total count, ordering, and pagination metadata. Key differentiator: seamless integration with egg-mysql, minimal configuration, supports both object-based where clauses and raw SQL strings. Ideal for Egg.js projects needing simple pagination without additional ORM or query builder complexity.

npm install egg-mysql-paginator
INSTALL
IMPORT
SIG · EGG-MYSQL-PAGINATO
E
egg-mysql-paginator
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mysqlPaginator
// Available as app.mysqlPaginator in Egg.js context after enabling plugin
const mysqlPaginator = require('egg-mysql-paginator');
This is a plugin, not a standalone module. Must be configured in config/plugin.js with enable: true and package: 'egg-mysql-paginator'.

Configures the plugin and performs a paginated query with object where clause and ordering.

// config/plugin.js exports.mysqlPaginator = { enable: true, package: 'egg-mysql-paginator', }; // In service/controller const results = await app.mysqlPaginator.query('users', { where: { status: 'active' }, orders: [['created_at', 'desc']], page: 1, size: 10 }); console.log(results); // { // pagination: { total: 100, size: 10, currentPage: 1, lastPage: 10, from: 0, to: 10 }, // data: [ ... ] // }
Debug
Known issues
gotchaPlugin requires egg-mysql to be enabled; mysqlPaginator will not work unless both plugins are configured.
fix
Ensure config/plugin.js includes both 'mysql' and 'mysqlPaginator' entries.
affects: >=0.0.0
deprecatedPackage has not been updated since 2020; may have compatibility issues with newer Egg.js versions (>=3).
fix
Consider migrating to newer pagination solutions or using raw queries with egg-mysql.
affects: >=1.0.0
gotchaThe 'where' option accepts an object OR a raw SQL string. Mixing both silently ignores the object if 'where' already exists as string (last write wins).
fix
Consistently use either object format or raw SQL strings, never both.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'egg-mysql-paginator'
Plugin not installed or not enabled in config/plugin.js
fix
Run 'npm install egg-mysql-paginator --save' and ensure config/plugin.js contains 'exports.mysqlPaginator = { enable: true, package: 'egg-mysql-paginator' };'
app.mysqlPaginator is not a function
The mysql plugin is not enabled or the mysqlPaginator plugin is not configured correctly; mysqlPaginator depends on app.mysql being available.
fix
Enable both 'mysql' and 'mysqlPaginator' plugins in config/plugin.js.
TypeError: Cannot read property 'query' of undefined
mysqlPaginator not initialized because egg-mysql plugin is not started or configuration is missing.
fix
Check that 'config.mysql' is correctly configured with database credentials and both plugins are enabled.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
egg-mysqlrequiredRequires egg-mysql plugin to be enabled, as mysqlPaginator queries against the same MySQL instance.
Agent activity
8 hits · last 30 days
node
6
Resources
egg-mysql-paginator — npm install egg-mysql-paginator · libregistry