mariadb npm code example
Example 1: install mariadb
sudo apt update
sudo apt-get -y install mariadb-server
sudo systemctl start mariadb
sudo systemctl enable mariadb
Example 2: install mariadb-server rpm
curl -sS https:
Example 3: 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);
const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
console.log(res);
} catch (err) {
throw err;
} finally {
if (conn) return conn.end();
}
}