<commit_before>var _ = require("lodash");
var q = require("q");
var moment = require("moment");

function SQLProxyServer(providerFactory) {
    this.providerFactory = providerFactory || this.defaultProviderFactory;
}

SQLProxyServer.prototype.defaultProviderFactory = function(url){
    var m = /([^:]*).*/.exec(url);
    if(!m) return q.reject("Invalid connection " + url);
    try{
      return q.resolve(require('./' + m[1] + "driver.js"));
    }catch(e){
      return q.reject(e);
    }
  }

SQLProxyServer.prototype.loadProvider = function(req){
    return this.providerFactory(req.url)
        .then(provider => {
          req.provider = new provider(req);
          return req;
        });
  } 

SQLProxyServer.prototype.loadAPI = function(req){
    return this.loadProvider(req)
            .then(d => new this.API(req));
  }

SQLProxyServer.prototype.execCommand = function(req){
    return this.loadAPI(req)
            .then(api => api.execute());
  }
SQLProxyServer.prototype.getConnection = function(req){
    var consrc = [/con\=(.*)/.exec(req.url)[1], req.query.con, req.body.url];
    req.body.url = consrc.filter(s => s)[0];
  }
SQLProxyServer.prototype.runStandalone = function(){
    var express = require('express');
    var bodyParser = require('body-parser');
    var app = express();
    
    app.use((req, res, next)=>{
        res.setHeader('Access-Control-Allow-Origin', '*');
        res.setHeader('Access-Control-Allow-Headers', 'Origin, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Response-Time, X-PINGOTHER, X-CSRF-Token,Authorization');
        res.setHeader('Access-Control-Allow-Methods', '*');
        res.setHeader('Access-Control-Expose-Headers', 'X-Api-Version, X-Request-Id, X-Response-Time');
        res.setHeader('Access-Control-Max-Age', '1000');
        return next();
    });

    app.use(bodyParser.json({
      strict: false,
      type: '*/*'    
    }));
    var oThis = this;
    app.get("/", function(req, res){
      oThis.getConnection(req);
      if(!req.query.con){
        return res.status(500).send("Missing parameter `con` with connection details. "
        + "Example: con=mssql://dbuser:dbpwd@sqlserver/databasename");
      }
      oThis.execCommand({url: req.query.con, type:'test'})
        .then(data => res.send(data))
        .catch(err => 
          res.status(500).send(err));
    });
    app.post("/*", function(req, res){
      oThis.getConnection(req);
      oThis.execCommand(req.body)
        .then(data => res.send(data))
        .catch(err => 
          res.status(500).send(err));
    });
    
    var port = process.argv[2] || 666;
    app.listen(port);
    console.log("Server is listening to port " + port);
  }

SQLProxyServer.prototype.API = function(command){
    var _api = this;
    _api.cmd = command;<commit_msg>to make url consistent with datasource.js<commit_after>var _ = require("lodash");
var q = require("q");
var moment = require("moment");

function SQLProxyServer(providerFactory) {
    this.providerFactory = providerFactory || this.defaultProviderFactory;
}

SQLProxyServer.prototype.defaultProviderFactory = function(url){
    var m = /([^:]*).*/.exec(url);
    if(!m) return q.reject("Invalid connection " + url);
    try{
      return q.resolve(require('./' + m[1] + "driver.js"));
    }catch(e){
      return q.reject(e);
    }
  }

SQLProxyServer.prototype.loadProvider = function(req){
    return this.providerFactory(req.url)
        .then(provider => {
          req.provider = new provider(req);
          return req;
        });
  } 

SQLProxyServer.prototype.loadAPI = function(req){
    return this.loadProvider(req)
            .then(d => new this.API(req));
  }

SQLProxyServer.prototype.execCommand = function(req){
    return this.loadAPI(req)
            .then(api => api.execute());
  }
SQLProxyServer.prototype.getConnection = function(req){
    var consrc = [/\??con\=(.*)/.exec(req.url||"con=")[1], req.query.con, req.body.url];
    req.body.url = consrc.filter(s => s)[0];
  }
SQLProxyServer.prototype.runStandalone = function(){
    var express = require('express');
    var bodyParser = require('body-parser');
    var app = express();
    
    app.use((req, res, next)=>{
        res.setHeader('Access-Control-Allow-Origin', '*');
        res.setHeader('Access-Control-Allow-Headers', 'Origin, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version, X-Response-Time, X-PINGOTHER, X-CSRF-Token,Authorization');
        res.setHeader('Access-Control-Allow-Methods', '*');
        res.setHeader('Access-Control-Expose-Headers', 'X-Api-Version, X-Request-Id, X-Response-Time');
        res.setHeader('Access-Control-Max-Age', '1000');
        return next();
    });

    app.use(bodyParser.json({
      strict: false,
      type: '*/*'    
    }));
    var oThis = this;
    app.get("/", function(req, res){
      if(!req.query.con){
        return res.status(500).send("Missing parameter `con` with connection details. "
        + "Example: con=mssql://dbuser:dbpwd@sqlserver/databasename");
      }
      oThis.getConnection(req);
      oThis.execCommand({url: req.query.con, type:'test'})
        .then(data => res.send(data))
        .catch(err => 
          res.status(500).send(err));
    });
    app.post("/*", function(req, res){
      oThis.getConnection(req);
      oThis.execCommand(req.body)
        .then(data => res.send(data))
        .catch(err => 
          res.status(500).send(err));
    });
    
    var port = process.argv[2] || 666;
    app.listen(port);
    console.log("Server is listening to port " + port);
  }

SQLProxyServer.prototype.API = function(command){
    var _api = this;
    _api.cmd = command;
{'fraction_non_alphanumeric': 0.17472508291150288, 'fraction_numerical': 0.007331122359923198, 'mean_word_length': 2.946280991735537, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '342665', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1818, 'n_words': 314}