1.0.1 • Published 6 years ago

egg-real-mysql v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

egg-real-mysql

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Description

this plugin based on promise-mysql package, and promise-mysql based on node-mysql, so you can simply use it

the version on EggJs

egg-real-mysql versionegg 2.x
2.x😁
1.x
0.x

Install

$ npm i egg-real-mysql --save

Usage

// {app_root}/config/plugin.js
exports.realMysql = {
  enable: true,
  package: 'egg-real-mysql',
};

Configuration

// {app_root}/config/config.default.js
exports.mysql = {
    client: {
        host: '127.0.0.1',
        port: '3306',
        user: 'root',
        password: 'root',
        database: 'example',
    },
    app: true,
    agent: false,
};

see config/config.default.js for more detail.

use on service

module.exports = app => {
    return class extends app.Service {
        async create(name) {
            let data = {
                id: '',
                name: name
            };
            const result = await this.app.mysql.query('insert into list set ?', [ data ]).then(rows => {
                return JSON.parse(JSON.stringify(rows));
            });
            return result;
        }
    };
};

Questions & Suggestions

Please open an issue

License

MIT