-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.js
More file actions
50 lines (46 loc) · 1.23 KB
/
sql.js
File metadata and controls
50 lines (46 loc) · 1.23 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
50
var mysql = require('mysql') ;
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'stalker',
database : 'chat'
});
connection.connect();
var resultFriends = [];
function resultFriendsSender(){
console.log(resultFriends);
}
var userID = 1;
var dbQuery = "SELECT * FROM friends WHERE friend_1='" + userID + "' OR friend_2='" + userID + "';";
connection.query(dbQuery, function(err, rows, fields){
if (!err){
var friendID = '';
rows.forEach(function(item, i, arr) {
if(item["friend_1"] == userID){
friendID = item["friend_2"];
}
else{
friendID = item["friend_1"];
}
console.log("Друг: " + friendID);
var length = arr.length;
var dbQuery = "SELECT * FROM users WHERE id='" + friendID + "';";
connection.query(dbQuery, length, function(err, rows, fields){
if (!err){
resultFriends.push(rows);
if(resultFriends.length == length){
sender();
console.log("ВЫзов");
}
}
else{
console.log('Error while performing Query.');
}
});
});
}
else{
console.log('Error while performing Query.');
}
});
console.log("end");