Skip to content

hiowenluke/mysql-cli-exec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

MIT

Copyright (c) 2019, Owen Luke

About

Execute the MySQL sql statements in CLI, return the result as an object array.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published