Registry / database / egg-cute-mysql

egg-cute-mysql

JSON →
library2.1.0jsnpmunverified

MySQL plugin for Egg.js framework (v2.1.0), providing MySQL database access with CRUD operations, transaction support, and multi-datasource capabilities. Currently stable with no major release cadence. Differentiators include built-in pagination, selectKey style (camelcase/underline), and Literal expressions. Compared to egg-mysql, it offers a more streamlined API with page/order helpers.

npm install egg-cute-mysql
INSTALL
IMPORT
SIG · EGG-CUTE-MYSQL
E
egg-cute-mysql
databasejavascriptv2.1.0
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.

Plugin config
exports.mysql = { enable: true, package: 'egg-cute-mysql' };
exports.mysql = { enable: true, package: 'egg-mysql' };
Configure in config/plugin.js to enable the plugin.
app.mysql
const result = await app.mysql.query(sql, values);
const result = await app.mysql.query(sql, values, callback);
app.mysql is a singleton injected on app if config.mysql.app = true.
app.mysql.get()
const client = app.mysql.get('db1');
const client = app.mysql['db1'];
For multi-datasource, use get() method by clientId.

Shows minimal plugin configuration and a controller query.

// config/plugin.js exports.mysql = { enable: true, package: 'egg-cute-mysql', }; // config/config.default.js exports.mysql = { client: { host: '127.0.0.1', port: '3306', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test', pageSize: 50, selectKey: 'Camelcase', }, app: true, agent: false, }; // app/controller/home.js class HomeController extends Controller { async index() { const posts = await this.app.mysql.query('select * from posts limit 10'); this.ctx.body = posts; } }
Debug
Known issues
gotchaselectKey option: default is 'Camelcase' but many expect 'Underline' or vice versa. Check your column naming convention.
fix
Set selectKey to 'Underline' if your database uses snake_case.
affects: >=1.0.0
breakingpage() expects result set with pagination, but SQL injection risk if passed directly without sanitization.
fix
Always use parameterized queries: app.mysql.page('select * from posts where title=:title', { title: 'Hello' })
affects: >=2.0.0
deprecatedBeginTransactionScope generator function deprecated. Use async/await in Egg 2.x.
fix
Use async/await: await app.mysql.beginTransactionScope(async (conn) => { ... }, ctx);
affects: >=2.0.0
gotchaAgent mode must be explicitly enabled: agent: true in config. Default is false.
fix
Set agent: true if you need access on agent process.
affects: >=1.0.0
breakingEgg 3.x may not be compatible. This plugin targets Egg 2.x and Node >=8.0.0.
fix
Use Egg 2.x or check plugin compatibility with Egg 3.x.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'egg-cute-mysql'
Package not installed or installed in wrong directory.
fix
Run: npm install egg-cute-mysql --save
app.mysql is undefined
Plugin not enabled or app:true missing in config.
fix
Check config/plugin.js has enable:true and package name correct. Ensure config.mysql.app = true in config/config.default.js
ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
MySQL connection credentials wrong or database not accessible.
fix
Verify host, port, user, password, and database in config. Ensure MySQL server is running.
TypeError: Cannot read property 'query' of undefined
Trying to access client from get() without proper clients config.
fix
Use config.mysql.clients object with clientId keys, and call app.mysql.get('clientId').query()
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
6
Resources
egg-cute-mysql — npm install egg-cute-mysql · libregistry