MySql

Connect to the MySQL database, execute a query, and view the results as an array list.

Usage

myQuery(<query>,<dBConfig>)

<dbConfig> : 
           {
                user?: string, 
                password?: string , 
                host?: string, 
                port?: number, 
                database?: string               
            }
  • Return data : <array> /* query result */

  • Please review the example below

tests/sample.1
/* LIBRARIES
*************/
const { sente } = require('#libraries');
const { myQuery } = sente;


/* TEST FLOW
*************/
test = async () => {
   
    // set sql query;
    let query = "select * from users;";

    // set db configs
    let dBConfig = {
        host: '<127.0.0.1>',
        port: <port>,
        database: '<dbName>',
        user: '<username>',
        password: '<password>',     
    };

    
    // execute query
    let query_result_rows = await myQuery(query,dBConfig);
    
    //print query results
    console.log(query_result_rows);
    
        
}

Last updated