Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ksdaemon/sails-hook-sequelize
Sails.js hook to use sequelize ORM
https://github.com/ksdaemon/sails-hook-sequelize
orm sails-hook sailsjs sequelize-orm
Last synced: 5 days ago
JSON representation
Sails.js hook to use sequelize ORM
- Host: GitHub
- URL: https://github.com/ksdaemon/sails-hook-sequelize
- Owner: KSDaemon
- License: mit
- Created: 2015-07-31T19:13:45.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2024-06-16T11:01:38.000Z (6 months ago)
- Last Synced: 2024-10-23T10:38:38.720Z (2 months ago)
- Topics: orm, sails-hook, sailsjs, sequelize-orm
- Language: JavaScript
- Size: 3.47 MB
- Stars: 67
- Watchers: 7
- Forks: 53
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# sails-hook-sequelize
Sails.js hook to use sequelize ORM[![NPM version][npm-image]][npm-url]
[![Build Status][gh-build-test-image]][gh-build-test-url]
[![Code coverage][coveralls-image]][coveralls-url]
[![MIT License][license-image]][license-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]# Installation
Install this hook with:
```sh
$ npm install sails-hook-sequelize --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.
**Important note:** `dialect` keyword MUST be present in connection or connection.options.
```javascript
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`
```javascript
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: { // Options must exists (even if empty) in order to consider this model a Sequelize model
tableName: 'user',
classMethods: {},
instanceMethods: {},
hooks: {},
scopes: {},
},
connection: 'NotDefaultModelsConnection' // Can be omitted, so default sails.config.models.connection will be used
};
```# Contributors
This project was originally created by Gergely Munkácsy (@festo).
Now is maintained by Konstantin Burkalev (@KSDaemon).# License
[MIT](./LICENSE)Thanks JetBrains for support! Best IDEs for every language!
[![JetBrains](https://user-images.githubusercontent.com/458096/54276284-086cad00-459e-11e9-9684-47536d9520c4.png)](https://www.jetbrains.com/?from=wampy.js)
[npm-url]: https://www.npmjs.com/package/sails-hook-sequelize
[npm-image]: https://img.shields.io/npm/v/sails-hook-sequelize.svg?style=flat[gh-build-test-url]: https://github.com/KSDaemon/sails-hook-sequelize/actions/workflows/build-and-test.yml
[gh-build-test-image]: https://github.com/KSDaemon/sails-hook-sequelize/actions/workflows/build-and-test.yml/badge.svg[coveralls-url]: https://coveralls.io/github/KSDaemon/sails-hook-sequelize
[coveralls-image]: https://img.shields.io/coveralls/KSDaemon/sails-hook-sequelize/master.svg?style=flat[license-image]: https://img.shields.io/badge/license-MIT-blue.svg
[license-url]: http://opensource.org/licenses/MIT[snyk-image]: https://snyk.io/test/github/KSDaemon/sails-hook-sequelize/badge.svg?targetFile=package.json
[snyk-url]: https://snyk.io/test/github/KSDaemon/sails-hook-sequelize?targetFile=package.json