0.1.8 • Published 5 years ago
mysql-cli-exec v0.1.8
MySQL CLI Exec
A MySQL command-line tool for Node.js. Execute the MySQL sql statements in CLI, return the result as an object array.
Installation
Install:
npm i mysql-cli-exec --save
Test:
git clone https://github.com/hiowenluke/mysql-cli-exec
cd mysql-cli-exec
npm install
npm test
Usage
Initialize:
const config = {
host: '127.0.0.1',
username: 'root',
password: 'playboy',
};
const myCli = require('mysql-cli-exec');
myCli.init(config);
Exec the sql statements:
const sql = `
use sys;
select * from sys_config;
`;
const result = myCli.exec(sql);
The result looks like below:
[
{
variable: 'diagnostics.allow_i_s_tables',
value: 'OFF',
set_time: '2019-09-20 06:53:50',
set_by: null
},
...
]
Examples
.do(sql)
const sql = `
use sys;
select * from sys_config;
`;
const result = myCli.do(sql);
result.length > 0 // true
.do(sql, config)
const sql = `
use sys;
select * from sys_config;
`;
const result = myCli.do(sql, config);
result.length > 0 // true
.do(sql, host)
const sql = `
use sys;
select * from sys_config;
`;
const host = 'localhost';
const result = myCli.do(sql, host);
result.length > 0 // true
.exec() // The alias of .do()
const sql = `
use sys;
select * from sys_config;
`;
const result = myCli.exec(sql); // myCli.do(sql)
result.length > 0 // true
License
Copyright (c) 2019, Owen Luke