Skip to main content

SELECT

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

¥The examples below also work for the execute method.

query(sql)

query(sql: string)

try {
const sql = 'SELECT * FROM `users` WHERE `name` = "Page" AND `age` > 45';

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

console.log(rows);
console.log(fields);
} catch (err) {
console.log(err);
}
  • rows 包含服务器返回的行

    ¥rows contains rows returned by server

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

    ¥fields contains extra meta data about rows, 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 = 'SELECT * FROM `users` WHERE `name` = "Page" AND `age` > 45';

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

console.log(rows);
console.log(fields);
} catch (err) {
console.log(err);
}
  • rows 包含服务器返回的行

    ¥rows contains rows returned by server

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

    ¥fields contains extra meta data about rows, if available

信息

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

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


query(options) — Row as Array

query(options: QueryOptions)

try {
const sql = 'SELECT * FROM `users` WHERE `name` = "Page" AND `age` > 45';

const [rows, fields] = await connection.query({
sql,
rowsAsArray: true,
// ... other options
});

console.log(rows);
console.log(fields);
} catch (err) {
console.log(err);
}
  • rows 包含服务器以数组形式返回的行

    ¥rows contains rows returned by server as array

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

    ¥fields contains extra meta data about rows, if available

信息

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

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


词汇表

¥Glossary

QueryOptions

QueryOptions Specification