M
M
Magnus Keef2018-12-12 18:41:04
css
Magnus Keef, 2018-12-12 18:41:04

How to display a table from sql server using tedious and ejs(node ​​js)?

I use Tedious to connect to sql server. The connection is working.

Here is the function
function queryDatabase() {
    request = new Request("SELECT * FROM officers", function (err, rowCount, rows) {
        console.log(rowCount + ' row(s) returned');
        //process.exit();
    });

    request.on('row', function (columns) {
        columns.forEach(function (column) {
            console.log("%s\t%s", column.metadata.colName, column.value);
            colOfficer.push(column.metadata.colName);
            valOfficer.push(column.value);

        });
    });

    connection.execSql(request);
}
which executes a query to the database and outputs to the console
. How do I change this function so that I can print data to ejs?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dima Pautov, 2016-01-29
@FoxPro111

https://www.google.ru/search?q=one+page+scroll&new...

W
westdp, 2016-01-29
@westdp

onepage
fullPage

Y
Yuri Oliyarnyk, 2016-01-29
@FoxPro111

Thank you

M
Magnus Keef, 2018-12-12
@SecurityYourFingers

Here is a function that allows you to fill the object driver{}

var driver = {};//создал объект
function queryDatabase() {
    request = new Request("SELECT * FROM [driving license] WHERE name_driver='Олег'", function (err, rowCount, rows) {
        console.log(rowCount + ' row(s) returned');
        //process.exit();
    });

    request.on('row', function (columns) {
        columns.forEach(function (column) {
            console.log("%s\t%s", column.metadata.colName, column.value);
            driver[column.metadata.colName] = column.value;//заполнение объекта
        });
    });

    connection.execSql(request);
}

Further, as soon as the connection passes, we use
this
ar connection = new Connection(config);
connection.on('connect', function (err) {
        if (err) {
            console.log(err);
        }
        else {
            queryDatabase(); //вот тут юзаем нашу функцию
        }
    }
)
function
and this is the use of the EJS template engine
app.get('/driver', function (req, res) {
  res.render('driver', {name:driver.name_driver, lastName:driver.last_name_driver, numPtc:driver.num_ptc, numLicense:driver.num_license});
});

Здесь я передаю на страницу свойства объекта name:driver.name_driver
А тут уже юзаю эту переменную name
<div class="header">
            <h1>Вы зашли как водитель: <%=name%></h1>
            <a href="http://localhost:3000/"><div class="btn-close">ВЫХОД</div></a>
        </div>

Who needs more details, write to VK

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question