Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sequelize remote database access

I have a database that i have previously been accessing (using php) remotely now i am trying to setup sequelize to connect to the same remote servers database:

for this i have the following json (database.json):

{
  "dev": {
    "server": "serverip",
    "driver": "mysql",
    "user": "username",
    "port": "3306",
    "database": "databasename",
    "password": "password"
  }
}

(ive excluded sensitive data)

Now the way i connect to the database from my server.js is:

    var env = app.get('env') == 'development' ? 'dev' : app.get('env');
var port = process.env.PORT || 8080;

var Sequelize = require('sequelize');

// db config
var env = "dev";
var config = require('./database.json')[env];
var password = config.password ? config.password : null;

// initialize database connection
var sequelize = new Sequelize(
    config.server,
    config.database,
    config.user,
    config.port,
    config.password,
    {
        logging: console.log,
        define: {
            timestamps: false
        }
    }
);

The "sad" thing about this is that i does not throw any errors but i know it is not connected because it does not collect any data from the database.

So what am i doing wrong?

like image 938
Marc Rasmussen Avatar asked Mar 25 '15 14:03

Marc Rasmussen


1 Answers

Look at the API docs for creating a new sequelize instance: http://docs.sequelizejs.com/en/latest/api/sequelize/

Only database, user and password should passed as arguments, the rest is in the options object.

var sequelize = new Sequelize(
    config.database,
    config.user,
    config.password,
    {
        port: config.port,
        host: config.server,
        logging: console.log,
        define: {
            timestamps: false
        }    
    }
);
like image 164
Jan Aagaard Meier Avatar answered Oct 03 '22 00:10

Jan Aagaard Meier