This repository has been archived on 2024-10-02. You can view files and clone it, but cannot push or open issues or pull requests.
2021-03-12 07:45:52 +00:00
|
|
|
const mariadb = require('mariadb');
|
2021-03-12 08:31:41 +00:00
|
|
|
const config = require('./config');
|
|
|
|
|
2021-03-12 07:45:52 +00:00
|
|
|
const pool = mariadb.createPool({
|
|
|
|
host: "test-db.verdnatura.es",
|
2021-03-12 08:58:11 +00:00
|
|
|
database: "vn",
|
2021-03-12 08:31:41 +00:00
|
|
|
user: config.userDev,
|
|
|
|
password: config.passwordDev,
|
2021-03-12 08:58:11 +00:00
|
|
|
port: 3307,
|
2021-03-12 07:45:52 +00:00
|
|
|
connectionLimit: 5
|
|
|
|
});
|
2021-03-12 08:06:38 +00:00
|
|
|
pool.getConnection()
|
|
|
|
.then(conn => {
|
|
|
|
|
|
|
|
conn.query("SELECT 1 as val")
|
|
|
|
.then(rows => { // rows: [ {val: 1}, meta: ... ]
|
|
|
|
return conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
|
|
|
|
})
|
|
|
|
.then(res => { // res: { affectedRows: 1, insertId: 1, warningStatus: 0 }
|
|
|
|
conn.release(); // release to pool
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
conn.release(); // release to pool
|
|
|
|
})
|
|
|
|
|
|
|
|
}).catch(err => {
|
|
|
|
//not connected
|
|
|
|
});
|