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-execcd mysql-cli-execnpm installnpm test
Usage
Initialize:
const config = host: '127.0.0.1' username: 'root' password: 'playboy'; const myCli = ;myCli;
Exec the sql statements:
const sql = ` use sys; select * from sys_config;`;const result = myCli;
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;resultlength > 0 // true
.do(sql, config)
const sql = ` use sys; select * from sys_config;`;const result = myCli;resultlength > 0 // true
.do(sql, host)
const sql = ` use sys; select * from sys_config;`;const host = 'localhost';const result = myCli;resultlength > 0 // true
.exec() // The alias of .do()
const sql = ` use sys; select * from sys_config;`;const result = myCli; // myCli.do(sql)resultlength > 0 // true
License
Copyright (c) 2019, Owen Luke