-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathdboperations.js
59 lines (45 loc) · 1.3 KB
/
dboperations.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
var config = require('./dbconfig');
const sql = require('mssql');
async function getOrders() {
try {
let pool = await sql.connect(config);
let products = await pool.request().query("SELECT * from Orders");
return products.recordsets;
}
catch (error) {
console.log(error);
}
}
async function getOrder(orderId) {
try {
let pool = await sql.connect(config);
let product = await pool.request()
.input('input_parameter', sql.Int, orderId)
.query("SELECT * from Orders where Id = @input_parameter");
return product.recordsets;
}
catch (error) {
console.log(error);
}
}
async function addOrder(order) {
try {
let pool = await sql.connect(config);
let insertProduct = await pool.request()
.input('Id', sql.Int, order.Id)
.input('Title', sql.NVarChar, order.Title)
.input('Quantity', sql.Int, order.Quantity)
.input('Message', sql.NVarChar, order.Message)
.input('City', sql.NVarChar, order.City)
.execute('InsertOrders');
return insertProduct.recordsets;
}
catch (err) {
console.log(err);
}
}
module.exports = {
getOrders: getOrders,
getOrder : getOrder,
addOrder : addOrder
}