Skip to content

willgriffin/sails-hook-sequeliz

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sails-hook-sequeliz

Sails.js V1 hook to use sequelize ORM V4

Installation

Install this hook with:

$ npm install sails-hook-sequeliz --save

Configuration

.sailsrc

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

Also you can set some parameters in config/sequelize.js to override defaults.

module.exports.sequelize = {
    "clsNamespace": "myAppCLSNamespace",
    "exposeToGlobal": true
};

Connections

Sequelize connection

somePostgresqlServer: {
  user: 'postgres',
  password: '',
  database: 'sequelize',
  dialect: 'postgres',
  options: {
    dialect: 'postgres',
    host   : 'localhost',
    port   : 5432,
    logging: console.log        // or specify sails log level to use ('info', 'warn', 'verbose', etc)
  }
}

Models

Sequelize model definition models/user.js

module.exports = {
  attributes: {
    name: {
      type: Sequelize.STRING,
      allowNull: false
    },
    age: {
      type: Sequelize.INTEGER
    }
  },
  associations: function() {
    user.hasMany(image, {
      foreignKey: {
        name: 'owner',
        allowNull: false
      }
    });
  },
  defaultScope: function() {
    return {
      include: [
        {model: image, as: 'images'}
      ]
    }
  },
  options: {
    tableName: 'user',
    classMethods: {},
    instanceMethods: {},
    hooks: {},
    scopes: {},
    connection: 'NotDefaultModelsConnection'    // Can be omitted, so default sails.config.models.connection will be used 
  }
};

Modified by Raymond FEST to match with Sails V0.12 old version applications

Contributors

This project was originally created by Gergely Munkácsy (@festo). Now is maintained by Konstantin Burkalev (@KSDaemon).

License

MIT [github-url]: https://github.com/aristot/sails-hook-sequeliz.git

About

ORM sequelize V4 hook for sails V1

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%