0

Is there a way to make them newline, if I break the line it will get an error but writing it this way will be quite unreadable. I use Sequelize

{
    const users = await db.sequelize.query(
        'SELECT count(name) as `counT` FROM users, reviews where users.id = reviews.userId group by users.name',
        {    
            type: QueryTypes.SELECT,
        }
    );
}
Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
  • Do you mean add a new line in the SQL query string? What about making it two string is different lines with `+`? – urban Jul 13 '21 at 14:05
  • 2
    https://stackoverflow.com/questions/805107/creating-multiline-strings-in-javascript – CBroe Jul 13 '21 at 14:09
  • "*if I break the line it will get an error*" - please show us how you tried to do that and what the error was. – Bergi Jul 13 '21 at 14:12
  • I'm voting to reopen - I believe the question requests a way to format SQL, not a way to insert newline characters into a string. There is obviously a relationship between these two concepts, but the linked question only concerns the latter. – Gershom Maes Jul 13 '21 at 14:17
  • As backticks (template literals) are used in the query, one option is to use single or double quotes with escaping the newline (with backslash) at end of line. Adding \n\ (newline and escaping the string newline) at the end of line is workaround. Having select, from, where and group on separate lines improves the readability. I also want to know how the others are doing this. Probably double quotes to keep it consistent with PHP. – Gergo Jul 13 '21 at 14:40

0 Answers0