我用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代码中做到这一点?
3条答案
按热度按时间vawmfj5a1#
我建议您将其拆分为子字符串,然后根据需要进行连接。
9o685dep2#
您可以使用一个用backticks表示的模板字符串来让您的字符串跨越多行,然后使用正则表达式删除任何行
\n
字符串中的字符。在你的例子中
这是有效的语法,是等效的。
vql8enpb3#
您可以使用代码格式化程序扩展名(prettier),它将自动重新格式化您的代码,并使其在保存文件时可读。