Convenient way to wrap long SQL statements in javascript

前端 未结 5 1549
别那么骄傲
别那么骄傲 2021-01-26 09:35

In python, one can use \"\"\" to wrap long MySQL statements. For example,

sql = \"\"\"CREATE TABLE EMPLOYEE (
         FIRST_NAME  CHAR(20) NOT NULL,
         L         


        
5条回答
  •  甜味超标
    2021-01-26 10:30

    Dealing with long strings in JavaScript:

    var sql = "CREATE TABLE EMPLOYEE (" +
                 " FIRST_NAME  CHAR(20) NOT NULL," +
                 " LAST_NAME  CHAR(20)," +
                 " AGE INT," +
                 " SEX CHAR(1)," +
                 " INCOME FLOAT )";
    

    Python's triple quotes are great! Unfortunately, in JavaScript, you have only two options:

    • + based concatenation, as above
    • \ based continuation, as proposed by @Nina Scholz

    Personally, I don't like using \ for line continuation (in any language.) Using + doesn't introduce unnecessary spaces in your string either.

    Hope this helps.

提交回复
热议问题