sequelize / sequelize

Feature-rich ORM for modern Node.js and TypeScript, it supports PostgreSQL (with JSON and JSONB support), MySQL, MariaDB, SQLite, MS SQL Server, Snowflake, Oracle DB (v6), DB2 and DB2 for IBM i.
https://sequelize.org/
MIT License
29.42k stars 4.26k forks source link

Sequelize and socksjs #9780

Open fukktalent opened 6 years ago

fukktalent commented 6 years ago

What are you doing?

I want to do Sequelize connects via a SOCKS connection. I find(https://devcenter.heroku.com/articles/fixie-socks#using-with-languages-that-don-t-support-socks-proxies) how connect mysql2 via a SOCKS connection. But I can't do that through Sequelize. Is it possible?

Through mysql2:

'use strict';

const SocksConnection = require('socksjs');
const mysql = require('mysql2');
const fixieUrl = process.env.FIXIE_SOCKS_HOST;
const fixieValues = fixieUrl.split(new RegExp('[/(:\\/@)/]+'));

const mysqlServer = {
  host: 'your-host.example.com',
  port: 3306
};

const dbUser = 'user';
const dbPassword = 'password';
const db = 'database';

const fixieConnection = new SocksConnection(mysqlServer, {
  user: fixieValues[0],
  pass: fixieValues[1],
  host: fixieValues[2],
  port: fixieValues[3],
});

const mysqlConnPool = mysql.createPool({
  user: dbUser,
  password: dbPassword,
  database: db,
  stream: fixieConnection
});

mysqlConnPool.getConnection(function gotConnection(err, connection) {

  if (err) throw err;

  queryVersion(connection);
});

function queryVersion(connection) {
  connection.query('SELECT version();', function (err, rows, fields) {

      if (err) throw err;

      console.log('MySQL/MariaDB version: ', rows);
      connection.release();
      process.exit();
  });
}

Dialect: mysql Dialect version: "mysql": "^2.15.0", "mysql2": "^1.6.1", Database version: 5.7.9 Sequelize version: 4.33.4 Tested with latest release: No (If yes, specify that version)

Note : Your issue may be ignored OR closed by maintainers if it's not tested against latest version OR does not follow issue template.

ashb commented 5 years ago

This would be possible if the connection manager's didn't filter dialectOptions but just passed it on directly to the underlying lib I think

ashb commented 5 years ago

Something else is going on here - I tried using https://github.com/rofl0r/proxychains-ng to automatically proxy via the SOCKS proxy, and If I use the pg lib directly (as in the example from fixiesocsk above) it works.

But when sequelize connection manager manages things it doesn't go via the proxy. I don't know how that's possible.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂

iamakimmer commented 4 years ago

Has anyone found a resolution to this?

ashb commented 4 years ago

I think I worked around this by doing proxychains4 node $(which sequelize) db:migrate instead of proxychains4 sequelize db:migrate -- I forget the exact reasoning, but it was something to do with shebang lines and how proxychains is injected in to procs, at least on OSX

papb commented 4 years ago

Related: #10973