Reputation: 309
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!
Upvotes: 0
Views: 1371
Reputation: 1348
This is a bug, and as @robertklep indicate, a workaround is to execute a conn.query("COMMIT") command.
But is jira.mariadb.org/browse/CONJS-52, and is now corrected with the latest release (2.0.1)
Upvotes: 1
Reputation: 203409
Looks like this is a bug in the MariaDB driver, where conn.commit()
doesn't actually commit. The bug is documented here.
In that comment, a workaround is suggested, by calling COMMIT
manually:
conn.query('COMMIT');
Also make sure that you end the connection when you're done, to release the connection back into the pool:
.then(()=>{
return conn.query("COMMIT").then(() => {
return conn.end();
});
})
.catch((err)=>{
return conn.query("ROLLBACK").then(() => {
conn.end();
throw new Error(err)
});
})
Upvotes: 1