I've searched already on the internet, but couldn't find a solution to my problem. I'm using NodeJS and a MariaDB with a pool connection. I get a connection from the pool, make a transaction (no errors) but I cannot see any chances inside my database. If I use the query without a transaction, just with pool.query(...) then it works fine. I know for just one query I wouldn't need a transaction, but I have just simplified the code for you.
pool.getConnection()
.then(conn =>{
conn.beginTransaction()
.then(() =>{
return conn.query("UPDATE Users SET forename='Tom' WHERE user_id=8")
})
.then(()=>{
console.log("commit")
conn.commit()
//conn.end() --> doesn't change anything
})
.catch((err)=>{
console.log(err.message);
conn.rollback()
})
});
What's wrong here?
Thanks!
conn.commit()you should try and useconn.query('COMMIT')). And FWIW, I think that you still need to callconn.end()when you're done with the transaction, to release the connection back to the pool.