2

I have this MySQL query which works fine in Node.js.

connection.query(
    'SELECT reading.device_id,' +
    'reading.temperature,' +
    'reading.humidity,' +
    'reading.light,' +
    'reading.time_taken ' +
    'FROM sensors.reading reading',
    function (err, results, fields) {
        console.log(results);
        console.log(fields);
    }

However, it is inconveniently adding those + signs at the end of each line of the query.

Can I do something like this in javascript similar to what is done in python?

connection.query(
    """SELECT reading.device_id,
        reading.temperature,
        reading.humidity,
        reading.light,
        reading.time_taken
    FROM sensors.reading reading""",
    function (err, results, fields) {
        console.log(results);
        console.log(fields);
    }

Of course, this won't work in javascript. But I am wondering how can I avoid adding those + signs at the end of each line in the query.

1 Answer 1

1

You can use the backslash:

connection.query(
  "SELECT reading.device_id,\
     reading.temperature,\
     reading.humidity,\
     reading.light,\
     reading.time_taken \
   FROM sensors.reading reading",
  function (err, results, fields) {
    console.log(results);
    console.log(fields);
  }
)

Be aware that this is quite undefined, as this is not part of the ECMA spec. It can break minifiers and may not be supported at all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.