engined-mysql
v0.0.6
Published
MySQL agent service for engined
Downloads
17
Readme
engined-mysql
MySQL agent service for engined, which is based on node-mysql2.
Installation
Install via NPM:
npm install engined-mysql
Usage
start mysql agent service in engined, see example below:
const { Manager } = require('engined');
const MySQLService = require('engined-mysql');
const MySQLDB = MySQLService({
agentName: 'MyDB', // optional: default to 'default' if not set
uri: 'mysql://localhost:3306/mydb'
});
const main = async () => {
// Create manager
let serviceManager = new Manager({ verbose: true });
// Adding agent to manager
serviceManager.add('MySQLDB', MySQLDB);
// Start all services
await serviceManager.startAll();
};
main();
Access MySQL Database
Pretty easy to get agent from context query database by node-mysql way.
let agent = this.getContext('MySQL').getAgent('MyDB');
// Querying
let ret = await agent.query('SELECT * FROM `mytable` WHERE `id` = ?', [ 1 ]);
License
Licensed under the MIT License
Authors
Copyright(c) 2017 Fred Chien(錢逢祥) <[email protected]>