Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // const mongoose = require('mongoose');
- // const credentials = require('./credentials');
- // const EndpointsModel = require('./models/EndpointsModel');
- //
- // const start = () => {
- // console.log('Trying to connect to MongoDB')
- // mongoose.connect(credentials)
- // .catch(start)
- // };
- //
- // const addEndpoint = (name, date) => {
- // new EndpointsModel({
- // endpoint: name,
- // creationDate: date,
- // }).save();
- // };
- //
- // const getEndpoint = (endpoint, callback) => {
- // EndpointsModel.findOne({endpoint: endpoint}, callback)
- // }
- const mysql = require('mysql');
- const sql = require('mssql');
- let connection;
- const addEndpoint = (endpoint, date) => {
- const article = {
- endpoint: endpoint,
- username: 'abt001',
- password: 'abt001',
- groupName: 'test-762-Dwg',
- groupId: 2385,
- };
- const query = connection.query('insert into endpoints set ?', article, function (err, result) {
- if (err) return console.error(err);
- console.log(query, result);
- });
- };
- const start = async () => {
- /* console.log('Trying to connect to SQL')
- connection = mysql.createConnection({
- host: 'localhost',
- user: 'Airbox_Application',
- password: 'CQwoxD7KLsrdIE7t8cnUKHw6oWV3XbZxXWOwOhP9LRcGnjR8lE83GNK5pjiZi75',
- database: 'rsvideo',
- // port: 1433
- // port: 3306
- port: 65240
- });
- console.log('hi')
- connection.connect();
- getEndpoint('hello')
- */
- const config = {
- user: 'Airbox_Application',
- password: 'CQwoxD7KLsrdIE7t8cnUKHw6oWV3XbZxXWOwOhP9LRcGnjR8lE83GNK5pjiZi75',
- server: 'localhost',
- database: 'rsvideo',
- port: 65240
- }
- const pool = await sql.connect(config);
- console.log('hello')
- const article = {
- endpoint: 'endpoint',
- username: 'abt001',
- password: 'abt001',
- groupName: 'test-762-Dwg',
- groupId: 2385,
- }
- // const result = await pool.request().query(`insert into endpoints (id, endpoint, username, password, groupName, groupId) VALUES (2, 'val', 'val', 'val','val', '324')`)
- const result = await pool.request().query('select * from endpoints')
- console.log('result', result)
- };
- const getEndpoint = (endpoint, callback) => {
- console.log('getEndpoint')
- const query = connection.query('select * from endpoints where endpoint = ?', endpoint, function (err, result) {
- if (err) return console.error(err);
- console.log(query.sql, result);
- callback({
- endpoint: endpoint,
- username: 'abt001',
- password: 'abt001',
- groupName: 'test-762-Dwg',
- groupId: 2385,
- })
- console.log('getEndpoint end')
- });
- };
- module.exports = {addEndpoint, start, getEndpoint};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement