connect nodejs to mariadb
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: 'mydb.com',
user:'myUser',
password: 'myPassword',
connectionLimit: 5
});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const rows = await conn.query("SELECT 1 as val");
console.log(rows); //[ {val: 1}, meta: ... ]
const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }
} catch (err) {
throw err;
} finally {
if (conn) return conn.end();
}
}
Also in JavaScript:
- curl post file json
- javascript switch case regex
- axios post with header
- Javascript change element class
- Truthy and Falsy js
- js for each item do
- npm stop react app
- array differenc javascript
- javascript object property + multilevel + optional chaining
- js copy array into another
- JS exercise bank account constructor functions and prototypes solution
- import switch material ui
- react mid senior dev interview questuions
- how to get tomorrow date in javascript
- await on observable
- for of and for in javascript
- how to pass props in react test cases
- dynsmic calss in react add
- node start is too slow windows 10
- react native gifted chat
- javascript pad with leading zeros
- how to draw a flower in javascript
- kendo datasource get
- binary to int javascript