1

I'm trying to use Sequelize to connect to my local install of Postgres. I installed it via Homebrew and have confirmed that I can connect and query the database just fine. When I run Sequelize it outputs valid queries (I ran them via console) but the database doesn't change and doesn't log any connection. My current code is:

var sequelize = new Sequelize('reliable_rabbit', 'mohammad', null, {
  host: "127.0.0.1",
  dialect: 'postgres',
  define: { timestamps: true, paranoid: true, underscore: true }//,
});

I can connect to the database via: psql -d reliable_rabbit -U mohammad -h 127.0.0.1. I am using version 1.5.0-beta of Sequelize.

Edit:

In my entry point (app/app.js), logs nothing:

var models = require('./models');
models.Post.sync().success(function(){
  console.log("Success!")
}).error(function(error){
  console.log("Error: " + error);
});

app/models.js:

var Sequelize = require("sequelize")

var sequelize = new Sequelize('reliable_rabbit', 'mohammad', null, {
  host: "127.0.0.1",
  logging: console.log,
  dialect: 'postgres',
  define: { timestamps: true, paranoid: true, underscore: true }//,
});
exports.Post = require("../models/post")(sequelize);

and finally models/post.js:

var Sequelize = require("sequelize");

module.exports = function(sequelize) {
  return sequelize.define('post', {
    title: { type: Sequelize.STRING, validate: { notEmpty: true } },
    permalink: { type: Sequelize.STRING, validate: { is: ["^[a-z]+[a-z\-][a-z]+$"] } },
    content: { type: Sequelize.TEXT, validate: { notEmpty: true } },
    published: { type: Sequelize.BOOLEAN, defaultValue: false },
    published_at: { type: Sequelize.DATE }
  },{
    instanceMethods: {
      generatePermalink: function() {
        this.permalink = this.title.toLowerCase().replace(/[^a-z]/g, "-").replace(/^-+|-+$/g,'').replace(/\-{2,}/g, '-');
      }
    }
  });
};
2
  • From what you say, I assume that postgresql is running on the default port and that u don't need a password, right? Can u maybe provide some more code? Commented Jul 9, 2012 at 5:44
  • Correct. I'll edit in the model and how I have it setup where it logs the query, but doesn't seem to execute it on the server. Commented Jul 10, 2012 at 4:08

1 Answer 1

1

first of all i would recommend the use of sequelize.import. furthermore i'm wondering if you probably just forgot to sync the database? Please let me know if you need further details about those things :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.