PUG wants to process mysql search results, recognizing field names with parentheses as a function. What should I do?

Asked 2 years ago, Updated 2 years ago, 41 views

Code for searching for mysql in node.js(express)

app.get('/record', function(req,res){
    sql = "select date_format(date, '%y-%m-%d') from record;"
    conn.query(sql, function(err, results){
        if(err){
            console.log(err)
        }else{
            console.log(results)
            res.render('record', {results:results})
        }
    })
})

In the console window, "date_format(date, '%y-%m-%d')": "20-03-18' is displayed like this.

If you do this to use it in a pug,

each result in results
                li=result.date_format(date, '%y-%m-%d')

result.date_format is not a function This error occurs.
Among the results of mysql search, I think it's because the field name is included in the field name, and js recognizes it as a function, so escape to prevent it? Is there a way?
Or can we arrange the field names that are printed without brackets?

javascript node.js mysql

2022-09-21 11:38

1 Answers

result.date_format()

If you say so, it's a function call

result['date_format()']

This is how you can use the property approach expression.


2022-09-21 11:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.