作为
docs
提到。我相信你有两种方法
async function getFixtures(leaguesArray) {
let response;
try {
response = await pool.query("SELECT * FROM fixtures WHERE league_name = ANY ($1)", [leaguesArray]));
} catch (e) {
console.error('Error Occurred', e);
}
return response.rows;
}
方法2
async function getFixtures(leaguesArray) {
let response;
const offset = 1;
const placeholders = leagueArray.map(function(name,i) {
return '$'+(i+offset);
}).join(',');
try {
response = await pool.query("SELECT * FROM fixtures WHERE league_name IN (" + placeholders+")", leaguesArray));
} catch (e) {
console.error('Error Occurred', e);
}
return response.rows;
}