-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_management.js
More file actions
50 lines (31 loc) · 1.24 KB
/
Copy pathquery_management.js
File metadata and controls
50 lines (31 loc) · 1.24 KB
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
// a function which return's date of today string in case date provided was "today"
function TodayDateStr(){
const today = Date()
var now = new Date(today)
var operationYear = now.getFullYear().toString();
var operationMonth = now.getMonth() + 1;
var operationDate = now.getDate().toString();
var todaydatestr = operationYear + "-" + operationMonth + "-" + operationDate;
return(todaydatestr)
}
// a function which constructs the SQL query, it takes the date and currency as positional arguments and returns the query as STR.
var queryconstruct = (currency,date)=>{
var Today = 'Today';
const SQLmap = { 'USD':'USDLYD','TRY':'TRYLYD',
'EUR':'EURLYD','CNY':'CNYLYD',
'TND':'TNDLYD', 'GBP': 'GBPLYD'};
var SQLTable = SQLmap[currency];
var Querydate = date
var test = Today.localeCompare(date, undefined, { sensitivity: 'accent' });
if (test == 0){
var Querydate = TodayDateStr()
}
else{
var Querydate = date
}
var SQLquery = `select * from ${SQLTable} where Price_Date = "${Querydate}"`;
return(SQLquery);
}
//Price_Date,Buy,Sell
//var q = queryconstruct('USD', '2020-10-11');
exports.queryconstruct = queryconstruct;