Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. (function() {
  2. var Gently, _a, mysql;
  3. mysql = require('mysql');
  4. Gently = require('gently');
  5. exports.Database = (function() {
  6. _a = function() {
  7. var Client;
  8. Client = mysql.Client;
  9. this.client = new Client();
  10. this.gently = new Gently();
  11. return this;
  12. };
  13. _a.prototype.connect = function(host, user, password, database) {
  14. this.client.user = "root";
  15. this.client.password = "root";
  16. this.client.host = "localhost";
  17. this.client.database = "filsh4";
  18. this.client.connect();
  19. if (this.client) {
  20. console.log(("MySQL connection to " + (host) + " established"));
  21. };
  22. return null;
  23. };
  24. _a.prototype.disconnect = function() {
  25. this.client.end();
  26. return null;
  27. };
  28. _a.prototype.getConfig = function(callback) {
  29. this.client.query('SELECT * FROM config', function(err, results, fields) {
  30. var _b, _c, _d, config, result;
  31. console.log(results);
  32. config = {};
  33. if ((err)) {
  34. throw err;
  35. }
  36. _c = results;
  37. for (_b = 0, _d = _c.length; _b < _d; _b++) {
  38. result = _c[_b];
  39. config[result.variable] = result.value;
  40. }
  41. callback(config);
  42. return null;
  43. });
  44. return null;
  45. };
  46. _a.prototype.getServerInfoById = function(id, callback) {
  47. // # The following query causes this error message:
  48. // #
  49. // #/Users/sascha/.node_libraries/mysql/query.js:42
  50. // # field = this._fields[0];
  51. // # ^
  52. // # TypeError: Cannot read property '0' of undefined
  53. // # at Query._handlePacket (/Users/sascha/.node_libraries/mysql/query.js:42:31)
  54. // # at Client._handlePacket (/Users/sascha/.node_libraries/mysql/client.js:194:14)
  55. // # at Parser.<anonymous> (/Users/sascha/.node_libraries/mysql/client.js:56:14)
  56. // # at Parser.emit (events:26:26)
  57. // # at Parser.write (/Users/sascha/.node_libraries/mysql/parser.js:479:16)
  58. // # at Stream.<anonymous> (/Users/sascha/.node_libraries/mysql/client.js:51:16)
  59. // # at Stream.emit (events:26:26)
  60. // # at IOWatcher.callback (net:512:16)
  61. // # at node.js:773:9
  62. this.client.query('SELECT * FROM `servers`', function(err, results, fields) {
  63. var result, server;
  64. console.log(results);
  65. if ((err)) {
  66. throw err;
  67. }
  68. result = results.first;
  69. server = result;
  70. callback(server);
  71. return null;
  72. });
  73. return null;
  74. };
  75. return _a;
  76. })();
  77. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement