From 7bde341f21fa1e02c783c50977b2fbfd2d41e9bd Mon Sep 17 00:00:00 2001 From: llopis15 Date: Fri, 12 Mar 2021 09:06:38 +0100 Subject: [PATCH] bd --- mariadb.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/mariadb.js b/mariadb.js index ff24168..28c096c 100644 --- a/mariadb.js +++ b/mariadb.js @@ -5,7 +5,20 @@ const pool = mariadb.createPool({ password: "llopis.19263", connectionLimit: 5 }); -pool.getConnection(){ - .then(conn => {} - - }) \ No newline at end of file +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 + }); \ No newline at end of file