forked from mhajah/projekt_weppo2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
searching_module.js
64 lines (47 loc) · 1.42 KB
/
searching_module.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
var mssql = require('mssql');
async function main() {
var conn = new mssql.ConnectionPool(
'server=localhost,1433;database=WEPPO;user id=weppo_sklep;password=weppo123');
try {
await conn.connect();
var request = new mssql.Request(conn);
var result = await request.query('select * from users');
result.recordset.forEach(r => {
console.log(`${r.ID} ${r.name}`);
})
await conn.close();
}
catch (err) {
if (conn.connected)
conn.close();
console.log(err);
}
}
main();
/*
//
const http = require("http")
var express = require("express");
var app = express();
app.post('/', (req, res,next) => {
const search_value = req.body.name;
//make question to the SQL or sth...app
var sql = require("mssql")
var config = {
server: 'localhost', //palceholder
datebase: 'Sklep'
};
//conencting to the datebase
sql.connect(config,function(err){
if (err) console.log(err);
//create Request object
var request = new sql.Request();
//querry to the datebase and get the records
request.query('SELECT * FROM [Sklep].[dbo].[goods] WHERE name LIKE \'%{$search_value}%\'',function (err, recordset){
if(err) console.log(err)
//sending recors as a response
res.send(recordset);
});
});
});
*/