1const mariadb = require('mariadb');
2const pool = mariadb.createPool({
3 host: 'mydb.com',
4 user:'myUser',
5 password: 'myPassword',
6 connectionLimit: 5
7});
8async function asyncFunction() {
9 let conn;
10 try {
11 conn = await pool.getConnection();
12 const rows = await conn.query("SELECT 1 as val");
13 console.log(rows); //[ {val: 1}, meta: ... ]
14 const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
15 console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }
16
17 } catch (err) {
18 throw err;
19 } finally {
20 if (conn) return conn.end();
21 }
22}
23