Advertisement
Guest User

Untitled

a guest
Apr 4th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. // const mongoose = require('mongoose');
  2. // const credentials = require('./credentials');
  3. // const EndpointsModel = require('./models/EndpointsModel');
  4. //
  5. // const start = () => {
  6. // console.log('Trying to connect to MongoDB')
  7. // mongoose.connect(credentials)
  8. // .catch(start)
  9. // };
  10. //
  11. // const addEndpoint = (name, date) => {
  12. // new EndpointsModel({
  13. // endpoint: name,
  14. // creationDate: date,
  15. // }).save();
  16. // };
  17. //
  18. // const getEndpoint = (endpoint, callback) => {
  19. // EndpointsModel.findOne({endpoint: endpoint}, callback)
  20. // }
  21.  
  22. const mysql = require('mysql');
  23. const sql = require('mssql');
  24. let connection;
  25.  
  26. const addEndpoint = (endpoint, date) => {
  27. const article = {
  28. endpoint: endpoint,
  29. username: 'abt001',
  30. password: 'abt001',
  31. groupName: 'test-762-Dwg',
  32. groupId: 2385,
  33. };
  34. const query = connection.query('insert into endpoints set ?', article, function (err, result) {
  35. if (err) return console.error(err);
  36. console.log(query, result);
  37. });
  38. };
  39.  
  40. const start = async () => {
  41. /* console.log('Trying to connect to SQL')
  42. connection = mysql.createConnection({
  43. host: 'localhost',
  44. user: 'Airbox_Application',
  45. password: 'CQwoxD7KLsrdIE7t8cnUKHw6oWV3XbZxXWOwOhP9LRcGnjR8lE83GNK5pjiZi75',
  46. database: 'rsvideo',
  47. // port: 1433
  48. // port: 3306
  49. port: 65240
  50. });
  51. console.log('hi')
  52. connection.connect();
  53. getEndpoint('hello')
  54. */
  55. const config = {
  56. user: 'Airbox_Application',
  57. password: 'CQwoxD7KLsrdIE7t8cnUKHw6oWV3XbZxXWOwOhP9LRcGnjR8lE83GNK5pjiZi75',
  58. server: 'localhost',
  59. database: 'rsvideo',
  60. port: 65240
  61. }
  62. const pool = await sql.connect(config);
  63. console.log('hello')
  64. const article = {
  65. endpoint: 'endpoint',
  66. username: 'abt001',
  67. password: 'abt001',
  68. groupName: 'test-762-Dwg',
  69. groupId: 2385,
  70. }
  71.  
  72. // const result = await pool.request().query(`insert into endpoints (id, endpoint, username, password, groupName, groupId) VALUES (2, 'val', 'val', 'val','val', '324')`)
  73. const result = await pool.request().query('select * from endpoints')
  74. console.log('result', result)
  75.  
  76. };
  77.  
  78. const getEndpoint = (endpoint, callback) => {
  79. console.log('getEndpoint')
  80. const query = connection.query('select * from endpoints where endpoint = ?', endpoint, function (err, result) {
  81. if (err) return console.error(err);
  82. console.log(query.sql, result);
  83. callback({
  84. endpoint: endpoint,
  85. username: 'abt001',
  86. password: 'abt001',
  87. groupName: 'test-762-Dwg',
  88. groupId: 2385,
  89. })
  90. console.log('getEndpoint end')
  91.  
  92. });
  93. };
  94.  
  95. module.exports = {addEndpoint, start, getEndpoint};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement