Guest User

Untitled

a guest
May 13th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. var mysql = require('mysql');
  2. var loki = require("lokijs");
  3.  
  4. var db = new loki('config/config.json', {
  5. autoload: true,
  6. autoloadCallback: databaseInitialize,
  7. autosave: true,
  8. autosaveInterval: 1000 // save every four seconds for our example
  9. });
  10.  
  11. function databaseInitialize() {
  12. // on the first load of (non-existent database), we will have no collections so we can
  13. // detect the absence of our collections and add (and configure) them now.
  14. var CurConnection = db.getCollection("CurConnection");
  15. if (CurConnection === null) {
  16. CurConnection = db.addCollection("CurConnection");
  17. }
  18. }
  19.  
  20. var CurConnection = db.getCollection("CurConnection");
  21. var rows = CurConnection.find({
  22. '$loki': {
  23. '$eq': 1
  24. }
  25. });
  26.  
  27. var row = rows[0];
  28.  
  29. var servername = row.selservername;
  30. var port = row.selport;
  31. var dbname = row.seldbname;
  32. var username = row.selusername;
  33. var password = row.selpassword;
  34.  
  35. var connection = mysql.createPool({
  36. multipleStatements: true,
  37. host: servername,
  38. port: port,
  39. user: username,
  40. password: password,
  41. database: dbname
  42. });
  43.  
  44. module.exports = connection;
Add Comment
Please, Sign In to add comment