Monday 19 November 2018

How to Render Two SQL Queries

I am very new to Node and am having trouble trying to get the results of two different queries and rendering them to a view. I'm able to get the results of the first query and display it in my View but I don't know how to get the results of the second query to display in the view.JS filefunction getData(callback) {new sql.ConnectionPool(config).connect().then(pool => {return pool.request().query("select Name from Items")}).then(result => {console.log('This is the recordset ' + result.recordset);callback(result.recordset);sql.close();}).catch(err => {res.status(500).send({ message: "${err}" })sql.close();});​new sql.ConnectionPool(config).connect().then(pool => {return pool.request().query("select Code from Customers")}).then(result => {console.log('This is the recordset for Terms ' + result.recordset);callback(result.recordset);sql.close();}).catch(err => {res.status(500).send({ message: "${err}" })sql.close();});}//add routeapp.get('/add', function (req, res) {getData(function (itemData) {res.render('add_item', {title: 'Add Item',items: itemData});});});​PUG Fileextends layout​block contentform(method='POST', action='/add')#form-group.rowdiv.col-sm-12label.lbl-form Chain:select.form-controleach item in itemsoption(value= item.Name)= item.Name#form-group.rowdiv.col-sm-6label.lbl-form Termsselect.form-controleach customer in customersoption(value= customer.Name)= customer.Name​​​

Submitted November 19, 2018 at 08:40PM by crashBandicoot61

No comments:

Post a Comment