Skip to main content

UPDATE

execute(sql, values)โ€‹

execute(sql: string, values: any[])

try {
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];

const [result, fields] = await connection.execute(sql, values);

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
  • fields contains extra meta data about the operation, if available
info

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


execute(options)โ€‹

execute(options: QueryOptions)

try {
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];

const [result, fields] = await connection.execute({
sql,
values,
// ... other options
});

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
  • fields contains extra meta data about the operation, if available
info

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


execute(options, values)โ€‹

execute(options: QueryOptions, values: any[])

try {
const sql = 'UPDATE `users` SET `age` = ? WHERE `name` = ? LIMIT 1';
const values = [20, 'Josh'];

const [result, fields] = await connection.execute(
{
sql,
// ... other options
},
values
);

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • result: contains a ResultSetHeader object, which provides details about the operation executed by the server.
  • fields contains extra meta data about the operation, if available
info

The connection used for the query (execute) can be obtained through the createConnection, createPool or createPoolCluster methods.


Glossaryโ€‹

ResultSetHeaderโ€‹

ResultSetHeader Specification

QueryOptionsโ€‹

QueryOptions Specification