reference
node에서 maridb 연결
permitSetMultiParamEntries 을 true로 설정해야 insert into table명 set ? 이 가능함
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: '127.0.0.1',
user:'user01',
password: '0000',
database: 'shop',
permitSetMultiParamEntries : true,
connectionLimit: 5
});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const data = { username: 'scott', password: '0000' };
const res = await pool.query("insert into emp set ? ",data) ;
console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }
const rows = await conn.query("SELECT * from emp");
console.log(rows);
} catch (err) {
throw err;
} finally {
if (conn) conn.end();
}
}
asyncFunction().then(() => {
pool.end();
});
mkdir shop
cd shop
npm init
npm install mariadb