Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eggplugin/mysql

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eggplugin/mysql

mysql plugin for egg

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

egg-mysql

mysql plugin for Egg.js

NOTE: This plugin just for integrate mysql into Egg.js, more documentation please visit https://github.com/fuxingZhang/mysql-promise

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

Install

$ npm i @eggplugin/mysql --save

Configuration

// {app_root}/config/plugin.js
exports.mysql = {
  enable: true,
  package: '@eggplugin/mysql',
};

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

Simple instance

// {app_root}/config/config.default.js
exports.mysql = {
  client: {
    user: '',
    host: '',
    database: '',
    password: ''
    // port: '3306',
    // ...
  },
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

Usage:

single query:

;(async () => {
  // you can access to pool instance by using app.mysql
  const pool = app.mysql;
  const { results, fields } = await pool.query('SELECT NOW()');
  console.log({ results, fields });
})().catch(console.error);

check out a client:

;(async () => {
  // you can access to pool instance by using app.mysql
  const pool = app.mysql;
  const client = await pool.getConnection();
  try {
    const res = await client.query('SELECT * FROM users WHERE id = ?', [1]);
    console.log(res.results[0]);
    const { results, fields } = await client.query('SELECT NOW()');
    console.log(results, fields);
  } finally {
    // Make sure to release the client before any error handling,
    // just in case the error handling itself throws an error.
    client.release();
    // Don't use the connection here, it has been returned to the pool.
  }
})().catch(console.error);

more documentation please visit https://github.com/fuxingZhang/mysql-promise

Multiple instance

exports.mysql = {
  // default configuration for all clients
  default: {
    port: 3306,
    connectionLimit: 10,
    // connectTimeout: 10000,
    // dateStrings: true
  },
  clients: {
    // clientId, access the pool instance by app.mysql.get('clientId')
    db1: {
      user: '',
      host: '',
      database: '',
      password: ''
    // ...
    },
    db2: {
      user: '',
      host: '',
      database: '',
      password: ''
      // ...
    },
    // ...
  },
  // load into app, default is open
  app: true,
  // load into agent, default is close
  agent: false,
};

Usage:

;(async () => {
  // you can access the pool instance by app.mysql.get('clientId')
  const pool1 = app.mysql.get('db1'); 
  const pool2 = app.mysql.get('db2'); 
  //
}).catch(console.error);

more documentation please visit https://github.com/fuxingZhang/mysql-promise

Questions & Suggestions

Please open an issue here.

License

MIT

Keywords

FAQs

Package last updated on 17 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc