Registry / database / bamei-module-mysql

bamei-module-mysql

JSON →
library0.0.12jsnpmunverified

A MySQL client module for the bamei framework, version 0.0.12. Provides MySQL connection pooling and query execution via the bamei context API. Designed for Node.js v6.0+, wraps the popular mysql package. No significant release cadence; minimal documentation in Chinese. Differentiator: integrates seamlessly with bamei's module system for configuration and context access.

npm install bamei-module-mysql
INSTALL
IMPORT
SIG · BAMEI-MODULE-MYSQL
B
bamei-module-mysql
databasejavascriptv0.0.12
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.

bamei-module-mysql
require('bamei').create(function(ctx) { ctx.module('mysql'); });
import mysql from 'bamei-module-mysql';
This is a bamei module, not a standalone package. Use bamei's create() to initialize and ctx.module() to load the MySQL module.
client
const client = ctx.get('mysql.client');
const client = require('bamei-module-mysql');
The MySQL client is accessed via ctx.get('mysql.client') after loading the module with ctx.module('mysql').
query
client.query('SELECT * FROM table WHERE id=?', [id], callback);
client.query('SELECT * FROM table WHERE id=' + id, callback);
Always use parameterized queries to prevent SQL injection. The mysql package supports ? placeholders.

Shows how to initialize the MySQL module with configuration and run a simple query.

// Install: npm install bamei bamei-module-mysql const bamei = require('bamei'); const app = bamei.create(function (ctx) { ctx.module('mysql', { host: process.env.MYSQL_HOST || '127.0.0.1', user: process.env.MYSQL_USER || 'root', password: process.env.MYSQL_PASSWORD || '', database: process.env.MYSQL_DATABASE || 'test' }); const client = ctx.get('mysql.client'); client.query('SELECT 1 AS solution', (err, results) => { if (err) throw err; console.log('The solution is:', results[0].solution); client.end(); }); }); app.run();
Debug
Known issues
gotchaModule must be loaded inside bamei.create() callback using ctx.module(). Direct require() does not work.
fix
Use require('bamei').create() and ctx.module('mysql') instead of importing the module directly.
affects: >=0.0.0
gotchaThe client is accessed via ctx.get('mysql.client') after loading the module, not via require().
fix
Ensure ctx.module('mysql') is called before ctx.get('mysql.client').
affects: >=0.0.0
gotchaThe underlying mysql package uses callbacks, not Promises. No built-in Promise support.
fix
Wrap in a Promise or use util.promisify() to use async/await.
affects: >=0.0.0
gotchaConnection configuration defaults to 127.0.0.1:3306 with empty user/password/database – insecure in production.
fix
Explicitly set host, user, password, database via ctx.module('mysql', {...}) using environment variables.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'bamei-module-mysql'
The package is not installed or is required incorrectly without bamei framework.
fix
Install: npm install bamei bamei-module-mysql --save. Then use require('bamei').create() pattern, not direct require().
TypeError: ctx.module is not a function
ctx.module is not available outside bamei.create() callback.
fix
Place ctx.module('mysql') inside bamei.create(function(ctx) { ... }) callback.
Error: getaddrinfo ENOTFOUND 127.0.0.1:3306
MySQL server is not running or host is unreachable.
fix
Ensure MySQL is running on the specified host:port. Use environment variables to configure connection.
Upgrade
Version history
0.0.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Amazon
1
OpenAI (training)
1
Resources
bamei-module-mysql — npm install bamei-module-mysql · libregistry