0

我在 node.js 中运行以下查询,我意识到它没有返回所有行。我做错了什么?

app.get('/', async (req, res) => {
try {
const result = await client.query(`SELECT * FROM ${TasksTableName}`);
res.json(result.rows);
} catch (err) {
console.error('failed to get data', err);
res.status(500).json({ error: err });
}
});
4

1 回答 1

0

您描述的行为是正常的。事实上,对 NoSQLClient.query 的每次调用都会返回结果集的一部分。使用查询的选项参数中的 迭代结果集QueryResult.continuationKey,直到结果集用完并且继续键为空。Ci-下面是一个例子

async function runQuery(client, stmt, limit) {
const opt = { limit };
let res;
console.log('Query results:');
do {
// Issue the query
res = await client.query(stmt, opt);
// Each call to NoSQLClient.query returns a portion of the
// result set. Iterate over the result set, using the
// QueryResult.continuationKey in the query's option parameter,
// until the result set is exhausted and continuation key is
// null.
for(let row of res.rows) {
console.log(' %O', row);
}

opt.continuationKey = res.continuationKey;
} while(res.continuationKey != null);
}
于 2021-06-02T08:30:03.163 回答