Skip to main content

UPDATE

以下示例也适用于 execute 方法。

¥The examples below also work for the execute method.

query(sql)

query(sql: string)

try {
const sql = 'UPDATE `users` SET `age` = 20 WHERE `name` = "Josh" LIMIT 1';

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

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • 结果:包含 ResultSetHeader 对象,该对象提供有关服务器执行的操作的详细信息。

    ¥result: contains a ResultSetHeader object, which provides details about the operation executed by the server.

  • fields 包含有关操作的额外元数据(如果可用)

    ¥fields contains extra meta data about the operation, if available

信息

用于查询(.query())的连接可以通过 createConnectioncreatePoolcreatePoolCluster 方法获得。

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


query(options)

query(options: QueryOptions)

try {
const sql = 'UPDATE `users` SET `age` = 20 WHERE `name` = "Josh" LIMIT 1';

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

console.log(result);
console.log(fields);
} catch (err) {
console.log(err);
}
  • 结果:包含 ResultSetHeader 对象,该对象提供有关服务器执行的操作的详细信息。

    ¥result: contains a ResultSetHeader object, which provides details about the operation executed by the server.

  • fields 包含有关操作的额外元数据(如果可用)

    ¥fields contains extra meta data about the operation, if available

信息

用于查询(.query())的连接可以通过 createConnectioncreatePoolcreatePoolCluster 方法获得。

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


词汇表

¥Glossary

ResultSetHeader

ResultSetHeader Specification

QueryOptions

QueryOptions Specification