我有下面的代码写在nodeJS.
async function GetSellerInfoByID({seller_user_id})
{
console.debug("Method : GetSellerInfoByID @user.service.js Calling...");
await clientDB.connect();
dataBaseData = await clientDB.query('select seller_profiles.user_id,seller_profiles.business_name,seller_profiles.status, buyer_profiles.first_name, images.image_url buyer_profiles.last_name, user_details.email from seller_profiles inner join user_details on user_details.user_id = seller_profiles.user_id left join address_books on address_books.id = seller_profiles.address_book_id left join phone_numbers on phone_numbers.id = seller_profiles.phone_number_id inner join buyer_profiles on buyer_profiles.user_id = seller_profiles.user_id left join images on images.id = seller_profiles.business_logo_id where seller_profiles.user_id = $1', [seller_user_id,]);
//dataBaseData = await clientDB.query('select * from user_auth_validation where user_username=$1', [username]);
if(dataBaseData.rows.length > 0)
{
// dataBaseData.rows.forEach(element => {
console.debug("data have.");
//userID = element.user_id;
// });
// console.debug(dataBaseData.rows);
}
else
{
console.debug("Error in entered data, Please Check you Data Again.");
}
clientDB.end();
return dataBaseData;
}
正如您所看到的,我的SQL查询总是希望在一行中。我希望显示如下:(为了可读性)
dataBaseData = await clientDB.query('select seller_profiles.user_id,seller_profiles.business_name,seller_profiles.status, buyer_profiles.first_name, images.image_url, buyer_profiles.last_name, user_details.email from seller_profiles
inner join user_details on user_details.user_id = seller_profiles.user_id left join address_books on address_books.id = seller_profiles.address_book_id
left join phone_numbers on phone_numbers.id = seller_profiles.phone_number_id
inner join buyer_profiles on buyer_profiles.user_id = seller_profiles.user_id
left join images on images.id = seller_profiles.business_logo_id
where seller_profiles.user_id = $1', [seller_user_id,]);
如何在VS代码中做到这一点?
你可以使用代码格式化器扩展(更漂亮),它会自动重新格式化你的代码,使其可读,无论何时你保存你的文件
我建议您将其拆分为子字符串,然后根据需要进行连接。