Sequelize will setup a connection pool on initialization so you should ideally only ever create one instance per database.

  1. host: 'localhost',
  2. dialect: 'mysql'|'mariadb'|'sqlite'|'postgres'|'mssql',
  3. pool: {
  4. max: 5,
  5. idle: 10000
  6. },
  7. // SQLite only
  8. });
  9. // Or you can simply use a connection uri
  10. var sequelize = new Sequelize('postgres://user:pass@example.com:5432/dbname');

The Sequelize constructor takes a whole slew of options that are available via the .

Many more options can be found in the Model API reference

The Sequelize constructor takes a define option which will be used as the default options for all defined models.

  1. var sequelize = new Sequelize('connectionUri', {
  2. timestamps: false // true by default
  3. }
  4. var User = sequelize.define('user', {}); // timestamps is false by default
  5. var Post = sequelize.define('post', {}, {
  6. timestamps: true // timestamps will now be true
  7. });

Basically a promise represents a value which will be present at some point - "I promise you I will give you a result or an error at some point". This means that

will never work! This is because user is a promise object, not a data row from the DB. The right way to do it is:

  1. User.findOne().then(function (user) {
  2. console.log(user.get('firstName'));