jimtxowebdeb / proyecto

0 stars 0 forks source link

heroku postgresql #3

Open zmwebdev opened 10 years ago

zmwebdev commented 10 years ago

MySQL en local y PostgreSQL en Heroku:

if (process.env.DATABASE_URL) {
    // the application is executed on Heroku ... use the postgres database 
    db = new Sequelize(process.env.DATABASE_URL);
  } else {
    // the application is executed on the local machine ... use mysql
    // var db = new sqlze('databasename', 'username', 'password',{
    db = new Sequelize('test', 'peru', 'peru',{
        dialect: 'mysql',
        port: 3306
    });
  }

De esta forma no haría falta transformar mysql a postgresql:

https://github.com/zmwebdev/node-express-examples/blob/master/05-database/sequelize-heroku/app.js

zmwebdev commented 10 years ago
app.get('/users/names', function(req, res) {

    // Raw query
    db.query('SELECT name FROM users').success(function(rows){
        // no errors
        console.log(rows);
        res.json(rows);
        // res.json(JSON.stringify(rows));
    });

});

Funciona!!

https://github.com/zmwebdev/node-express-examples/blob/master/05-database/sequelize-heroku/app.js