-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.js
43 lines (36 loc) · 1.2 KB
/
database.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
var mysql = require('mysql');
var database = {
getFirstTenRows: function getFirstTenRows(query, callback){
var mysql = require('mysql');
// Add the credentials to access your database
var connection = mysql.createConnection({
host : '167.250.5.44',
user : 'grupogcp_electron',
password : 'rdk0UoYirk',
database : 'grupogcp_inandout'
});
// connect to mysql
connection.connect(function(err) {
// in case of error
if(err){
console.log(err.code);
console.log(err.fatal);
}
console.log("Connection established");
});
connection.query(query, function(err, rows, fields) {
if(err){
console.log("An error ocurred performing the query.");
console.log(err);
return;
}
callback(rows);
console.log("Query succesfully executed");
});
// Close the connection
connection.end(function(){
// The connection has been closed
});
}
};
module.exports = database;