This topic was automatically generated from Slack. You can find the original thread here.
Hi everyone,
Can anyone help me?
I am getting “connect ETIMEDOUT” error when using mysql2/promise with the code below.
The main purpose is to manage transactions so if there is any other solution instead of mysql2/promise that is also fine.
import mysql from 'mysql2/promise';
export default defineComponent({
props: {
mysql: {
type: "app",
app: "mysql",
description: "Connect to your MySQL database"
}
},
async run({ steps, $ }) {
let connection;
try {
connection = await mysql.createConnection({
host: this.mysql.$auth.host,
port: this.mysql.$auth.port,
user: this.mysql.$auth.username,
password: this.mysql.$auth.password,
database: this.mysql.$auth.database,
ssl: {
rejectUnauthorized: true,
},
});
await connection.beginTransaction();
await connection.execute("INSERT INTO test (doc) VALUES (?)", ["test"]);
await connection.execute("INSERT INTO test (doc) VALUES (?)", ["test2"]);
await connection.execute("INSERT INTO test (doc) VALUES (?)", ["test3"]);
await connection.commit();
} catch (error) {
console.error(error);
if (connection) {
await connection.rollback();
}
throw error;
} finally {
if (connection) {
await connection.end();
}
}
},
});