Code Monkey home page Code Monkey logo

mysql-cli-exec's Introduction

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

mysql-cli-exec's People

Contributors

hiowenluke avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.