Skip to content

Latest commit

 

History

History
81 lines (70 loc) · 1.44 KB

README.md

File metadata and controls

81 lines (70 loc) · 1.44 KB

sails-hook-sequelize

Sails.js hook to use sequelize ORM

Build Status npm version

#Install

Install this hook with:

$ npm install sails-hook-sequelize --save

Configuration

.sailsrc

{
  "hooks": {
    "orm": false,
    "pubsub": false
  }
}
```

## Connections
Sequelize connection
```javascript
somePostgresqlServer: {
  user: 'postgres',
  password: '',
  database: 'sequelize',
  dialect: 'postgres',
  options: {
    dialect: 'postgres',
    host   : 'localhost',
    port   : 5432,
    logging: console.log
  }
}
```

## Models
Sequelize model definition
`models/user.js`
```javascript
module.exports = {
  attributes: {
    name: {
      type: Sequelize.STRING,
      allowNull: false
    },
    age: {
      type: Sequelize.INTEGER
    }
  },
  associations: function() {
    user.hasMany(image, {
      foreignKey: {
        name: 'owner',
        allowNull: false
      }
    });
  },
  options: {
    tableName: 'user',
    classMethods: {},
    instanceMethods: {},
    hooks: {}
  }
};
```

## Migrations
If sails.config.models.migrate is set to 'umzug', the Sequelize Umzug library will be used to migrate up to the last version.
Migration files should be in the migrations folder.

#License
[MIT](./LICENSE)