2023-02-26 01:30
This commit is contained in:
34
mariadb/mariadb.js
Normal file
34
mariadb/mariadb.js
Normal file
@@ -0,0 +1,34 @@
|
||||
const mariadb = require('mariadb');
|
||||
const pool = mariadb.createPool({
|
||||
host: '192.168.50.5',
|
||||
port: 3307,
|
||||
database: 'test',
|
||||
user: 'elex',
|
||||
password: 'uwWwi7tzAjw8wBwJ',
|
||||
connectionLimit: 5
|
||||
});
|
||||
pool.getConnection()
|
||||
.then(conn => {
|
||||
//conn.batch
|
||||
conn.query("SELECT * from settings;")
|
||||
.then((rows) => {
|
||||
console.log(rows); //[ {val: 1}, meta: ... ]
|
||||
//Table must have been created before
|
||||
// " CREATE TABLE myTable (id int, val varchar(255)) "
|
||||
return conn.query("INSERT INTO settings (name, value) values (?, ?);", ['test2', "TEST"]);
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }
|
||||
conn.end();
|
||||
})
|
||||
.catch(err => {
|
||||
//handle error
|
||||
console.log(err);
|
||||
conn.end();
|
||||
}).finally(() => {
|
||||
pool.end();
|
||||
})
|
||||
|
||||
}).catch(err => {
|
||||
//not connected
|
||||
});
|
||||
Reference in New Issue
Block a user