1

In my node.js project I installed mysql and made this DB.js that queries the database. I'm stumped on how exactly would I query the database from the jade view.

To clarify my question, in .NET I would've returned an IQueryable from repositories and then expand the query inside the ASP.NET MVC controller, but what's the correspondent of that practice here in node? Is there even such a concept of a controller?

So how to query the database and return only what you need in the view, while also not exposing "too much" of the database in the view itself?

1 Answer 1

2

If you want to pass data from MySQL to a jade view in express (your question does not mention express but it is probably express)

test.jade

table
  tr
    th Name
    th Value
  - each x in data
    tr
      td #{x.name}
      td #{x.value}

NodeJS:

app.get("/getViews/:price", function(req,res){
  mysql.query("SELECT name, value FROM mytable WHERE price > ?", [price], function(err,fields,rows){
    res.render("test", {data: rows});
  });
});
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.