[英]How to span single line into multiple lines in VS code?
I have the following code written in nodeJS..我有以下用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;
}
As you could see, my SQL query always wants to be in one line.如您所见,我的 SQL 查询总是希望在一行中。 I wanted to be displayed as follows : (for readability)
我想显示如下:(为了可读性)
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,]);
How could I do that in VS code ?我怎么能在 VS 代码中做到这一点?
我建议您将其拆分为子字符串,然后根据需要进行连接。
You can use a template string denoted with backticks to let your string span multiple lines, then use a regex remove any \\n
characters from the string.您可以使用用反引号表示的模板字符串让您的字符串跨越多行,然后使用正则表达式从字符串中删除任何
\\n
字符。
In your example在你的例子中
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`
.replace(/[\n]/g, ""),
[seller_user_id]
);
This is valid syntax and is equivalent.这是有效的语法并且是等效的。
您可以使用代码格式化程序扩展 ( prettier ),它会在您保存文件时自动重新格式化您的代码并使其可读。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.