-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.js
155 lines (133 loc) · 3.23 KB
/
base.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var mysql = require('mysql');
class bd
{
constructor()
{
this.con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
}
createConexion()
{
this.con = mysql.createConnection({
host: "localhost",
user: "yourusername",
password: "yourpassword",
database: "mydb"
});
this.con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
var sql = "INSERT INTO customers (name, address) VALUES ('Company Inc', 'Highway 37')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("1 record inserted");
});
});
}
buscarUsuariobyname(name)
{
//Buscamos usuario por nombre
//Retorna id
}
insertNewUser(x_name,x_lastname,x_id,x_password,x_email,x_money)
{
//Guarda un nuevo usario en la base de datos
this.con.connect(function(err) {
if (err) throw err;
console.log("Connected to databse!");
var sql = "INSERT INTO users (name, lastname,userid,password,email,money) VALUES ('" + x_name"', '" + x_lastname + "', '" + x_id + "', '" + x_password + "', '" + x_email + "', '" + x_money + "')";
con.query(sql, function (err, result) {
if (err) throw err;
console.log("User inserted sucessfull");
});
});
}
estaId(id)
{
//Verifica si ese id esta en la base de datos
this.con.connect(function(err) {
if (err) throw err;
con.query("SELECT id FROM users WHERE userid == '"+id+"'", function (err, result, fields) {
if (err) throw err;
console.log(fields);
if(Object.keys(fields).length == 0){return false}
return true;
});
});
}
gerUsers()
{
//Retorna todos los usarios
this.con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM users", function (err, result, fields) {
if (err) throw err;
console.log(result);
});
});
}
getUser(id)
{
//Retorna usuario en un json
this.con.connect(function(err) {
if (err) throw err;
con.query("SELECT name, lastname, email, money FROM users WHERE userid == '"+id+"'", function (err, result, fields) {
if (err) throw err;
console.log(fields);
return fields;
});
});
}
getPassword(id)
{
//Retorna un hash con la clave
this.con.connect(function(err) {
if (err) throw err;
con.query("SELECT password FROM users WHERE userid == '"+id+"'", function (err, result, fields) {
if (err) throw err;
console.log(fields);
return fields;
});
});
}
deleteUser(id)
{
//borra usuario de base de datos
}
getMoney(id)
{
//retorna el dinero por el id
this.con.connect(function(err) {
if (err) throw err;
con.query("SELECT money FROM users WHERE userid == '"+id+"'", function (err, result, fields) {
if (err) throw err;
console.log(fields);
return fields;
});
});
}
updateMoney(id)
{
//Actualiza dinero (cantidad) dentro de la base de datos
}
updateName(id)
{
//Actualiza name dentro de la base de datos
}
updateLastname(id)
{
//Actualiza Lastname dentro de la base de datos
}
updateEmail(id)
{
//Actualiza email dentro de la base de datos
}
updatePassword(id)
{
//Actualiza password dentro de la base de datos
}
}